memset(3)
fill memory with a constant byte
Summary
memset() fills the first n bytes of a memory area with a single constant byte value. It is the standard way to initialize or clear a buffer in C, for example zeroing out a struct or array before use. It returns a pointer to the same memory area you passed in.
Description
memset
NAME
memset - fill memory with a constant byte
LIBRARY
Standard C library (libc, -lc)
SYNOPSIS
#include <string.h>
void *memset(void s[.n], int c, size_t n);
DESCRIPTION
The memset() function fills the first n bytes of the memory area pointed to by s with the constant byte c.
RETURN VALUE
The memset() function returns a pointer to the memory area s.
ATTRIBUTES
|
For an explanation of the terms used in this section, see attributes(7). |

STANDARDS
POSIX.1-2001, POSIX.1-2008, C99, SVr4, 4.3BSD.
SEE ALSO
bstring(3), bzero(3), swab(3), wmemset(3)
Examples
char buf[256];
memset(buf, 0, sizeof(buf));
Zero out an entire buffer before using it.
struct config cfg;
memset(&cfg, 0, sizeof(cfg));
Clear all fields of a struct to zero in one call.
char line[80];
memset(line, '-', sizeof(line));
Fill a buffer with a repeated byte value (here the dash character).