Jump to: navigation, search

Prototype

Declared in string.h

The C89/C99 prototype is:

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

Description

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.

Implementation

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;
    while(n--)
        *p++ = (unsigned char)c;
    return s;
}

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

References

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