##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# memset

From cppreference.com
< c‎ | string‎ | byte

Defined in header `<string.h>` |  |
void* memset( void* dest, int ch, size_t count ); |  |

Converts the value `ch` to unsigned char and copies it into each of the first `count` characters of the object pointed to by `dest`.

### [edit] Parameters

dest | - | pointer to the object to fill
ch | - | fill byte
count | - | number of bytes to fill

### [edit] Return value

`dest`

### [edit] Example

Run this code

    #include <stdio.h>
    #include <string.h>

    int main(void)
    {
        char str[] = "ghghghghghghghghghghgh";
        puts(str);
        memset(str,'a',5);
        puts(str);
        return 0;
    }

Output:

    ghghghghghghghghghghgh
    aaaaahghghghghghghghgh

### [edit] See also

memcpy | copies one buffer to another (function) [edit]
C++ documentation for memset

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=c/string/byte/memset&oldid=70104"