Easy Tutorial
❮ C Function Fputc C Function Atexit ❯

C Library Function - memset()

C Standard Library - <string.h>

Description

The C library function void *memset(void *str, int c, size_t n) copies the character c (an unsigned char) to the first n characters of the string pointed to by the argument str.

Declaration

Here is the declaration for the memset() function.

void *memset(void *str, int c, size_t n)

Parameters

Return Value

This function returns a pointer to the memory area str.

Example

The following example demonstrates the use of the memset() function.

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

int main ()
{
   char str[50];

   strcpy(str,"This is string.h library function");
   puts(str);

   memset(str,'$',7);
   puts(str);

   return(0);
}

Let's compile and run the above program, which will produce the following result:

This is string.h library function
$$$$$$$ string.h library function

C Standard Library - <string.h>

❮ C Function Fputc C Function Atexit ❯