Namespaces
Variants
Views
Actions

std::memset

From cppreference.com
< cpp | string | byte
Revision as of 21:57, 19 April 2012 by P12bot (Talk | contribs)

Template:cpp/string/byte/sidebar

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 dest+size+1 points outside the object, the behavior is undefined.

Contents

Parameters

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

Return value

dest

Example

#include <iostream>
#include <cstring>
 
int main()
{
    int a[20];
    std::memset(a, 0, sizeof(a));
    std::cout << "a[0] = " << a[0] << '\n';
}

Output:

a[0] = 0

See also

Template:cpp/string/byte/dcl list memcpyTemplate:cpp/algorithm/dcl list fill n
checks if a type is trivially copyable
(class template) [edit]