codescracker


c

C memset()



« Previous Chapter Next Function »


memset()

The memset() function copies the low-order byte of ch into the first count characters of the array pointed to by buf. It returns buf.

The most common use of memset() is to initialize a region of memory to some known value.

memset() Syntax

Following is the syntax of the memset() function :

#include<string.h>
void *memset(void *buf, int ch, size_t count);

memset() Example

Following code fragment initializes to null the first 100 bytes of the array pointed to by buf. Then it sets the first 10 bytes to X and displays the string XXXXXXXXXX.

memset(buf, '\0', 100);
memset(buf, 'X', 10);
printf(buf);

« Previous Chapter Next Function »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test