< cpp‎ | string‎ | byte
Defined in header <cstring>
void* memset( void* dest, int ch, std::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. If the object is not trivially-copyable (e.g., scalar, array, or a C-compatible struct), the behavior is undefined. If count is greater than the size of the object pointed to by dest, the behavior is undefined.


[edit] Parameters

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

[edit] Return value


[edit] Example

#include <iostream>
#include <cstring>
int main()
    int a[20];
    std::memset(a, 0, sizeof(a));
    for (int ai : a) std::cout << ai;



[edit] See also

copies one buffer to another
assigns a value to a number of elements
(function template)
checks if a type is trivially copyable
(class template)
C documentation for memset