Copyright © tutorialspoint.com

C - memset function

previous

Synopsis:

#include <stdio.h>

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

Description:

The memset function sets the first n bytes in s to c. Generally this function is used to set a memory location to null chracters '\0'.

Return Value

The memset function returns s with the set value to c

Example

#include <stdio.h>

int main() {
  char string[20];

  strcpy(string, "Hello");
  printf( "Before using memset |%s|\n", string );
  memset( string, '\0', sizeof(string) );
  printf( "After using memset |%s|\n", string );

  return 0;
}

It will proiduce following result:

Before using memset |Hello|
After using memset ||

previous

Copyright © tutorialspoint.com