Jump to: navigation, search


Declared in string.h

The C89/C99 prototype is:

void *memset(void *s, int c, size_t n);


The memset function copies the value of c (converted to an unsigned char) into each of the first n characters of the object pointed to by s.

Return value

The memset function returns the value of s.


In standard C, this can be implemented as:

#include <stddef.h> /* size_t */
void *memset(void *s, int c, size_t n)
    unsigned char* p=s;
        *p++ = (unsigned char)c;
    return s;

Compilable unit, portable C90 in implementation namespace; public domain; past reviewers: none; current reviews: none


  • The C Standard, (C99 numbering)
  • FAQ question 7.31 What's the difference between calloc and malloc?
Personal tools