Skip to main content Link Menu Expand (external link) Document Search Copy Copied

memset function

C

Function

Reference manual

@see man memset

The memset function sets the first n bytes of the memory area pointed to by ptr to the specified byte value.

Syntax

void *memset(void *ptr, int value, size_t n);

Parameters

  • ptr: A pointer to the memory area to be filled.
  • value: The byte value to be set (usually in the range 0 to 255).
  • n: The number of bytes to be set.

Return value

Returns a pointer to the memory area ptr.

Example

In the following example we use the memset function to fill the first 10 bytes of a character array to the character ‘A’.

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

int main(void) {
    char str[20];
    
    memset(str, 'A', 10);
    printf("Filled string: %s\n", str);
    return (0);
}