-
Contributing Member
Memory Function in C
What is the memset command used for C. is it used for setting fixed memory locations. I am making a wild guess from the name. Someone correct me if I am wrong. Also tell me what header files I have to include while using this command.
-
Contributing Member
Re: Memory Function in C
The memset is mainly used to initialize or set memory section with some value.
The syntax of memset is
void *memset( void *buffer, int c, count );
In this memset copies the value of c into the first count characters of buffer, and returns buffer. The header file that must be included while using this function is <string.h>
-
Expert Member
Re: Memory Function in C
The declaration of memset function is as follows
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' The memset function returns s with the value set to c
For example consider the code
#include<string.h>
#include<stdio.h>
void main()
{
char str[]="geekinterview";
printf("length before using memset =%d",strlen(str));
memset(str,'\0',sizeof(str));
printf("\nlength after using memset =%d",strlen(str)); getch(); }
output
length before using memset 13
length after using memset 0
Last edited by aman15490; 02-18-2010 at 09:42 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules