Tuesday, 17 January 2012

C - memset

#include <stdio.h>
void* memset(void* s, int c, int n);
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
#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 ||

No comments:

Post a Comment

host gator coupon