C programming string.h function - void *memset(void *str, int c, size_t n)

The memset() function in the string.h library is used to fill a block of memory with a specified value. The function signature is:

re‮f‬er to:theitroad.com
void *memset(void *str, int c, size_t n);

Here, str is a pointer to the block of memory to be filled, c is the value to be set, and n is the number of bytes to be set to the value c.

The memset() function returns a pointer to the block of memory str.

Here is an example usage of memset():

#include <string.h>
#include <stdio.h>

int main() {
    char str[50];
    
    // Fill the first 10 bytes of the str array with the value 'A'
    memset(str, 'A', 10);
    
    printf("%s\n", str); // Output: AAAAAAAAA
    
    return 0;
}