On this page
memset
Prev: memmove | Up: string.h | Next: memcmp
Rel: string.h, stdlib.h & string.h Guide
Ref: cppreference — memset
Tags: #public #prog #c #stdlib #string #tier/core
Include
#include <string.h>
Signature & Overview
void *memset(void *dst, int ch, size_t n);
Fills n bytes starting at dst with (unsigned char)ch.
Notes & Pitfalls
- Fills bytes, not multi-byte ints:
memset(int_arr, 1, sizeof(int_arr))sets every int to0x01010101, NOT1—only0and-1(0xFF) work as expected on ints.
Example
#include <assert.h>
#include <string.h>
int main(void) {
int arr[4];
memset(arr, 0, sizeof(arr));
assert(arr[0] == 0 && arr[3] == 0);
}
Linked from
Related notes
- tuts/c/stdlib/string/memcmp Linked here; links to this page; shared tags: #c, #prog, #stdlib, #string, #tier
- tuts/c/stdlib/string/memmove Linked here; links to this page; shared tags: #c, #prog, #stdlib, #string, #tier
- tuts/c/stdlib/string Linked here; links to this page; shared tags: #c, #prog, #stdlib, #string
- tuts/c/stdlib/stdlib_and_string_h Linked here; shared tags: #c, #prog, #stdlib
- tuts/c/stdlib/string/memchr shared tags: #c, #prog, #stdlib, #string, #tier
- tuts/c/stdlib/string/memcpy shared tags: #c, #prog, #stdlib, #string, #tier
- tuts/c/stdlib/string/strcat shared tags: #c, #prog, #stdlib, #string, #tier
- tuts/c/stdlib/string/strchr shared tags: #c, #prog, #stdlib, #string, #tier
- tuts/c/stdlib/string/strcmp shared tags: #c, #prog, #stdlib, #string, #tier
- tuts/c/stdlib/string/strcpy shared tags: #c, #prog, #stdlib, #string, #tier