Results 1 to 3 of 3

Thread: Memory Function in C

  1. #1
    Contributing Member
    Join Date
    Jul 2006
    Answers
    74

    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.


  2. #2
    Contributing Member
    Join Date
    May 2006
    Answers
    82

    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>


  3. #3
    Expert Member
    Join Date
    May 2008
    Answers
    100

    Thumbs up 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 08:42 AM.

  4.  Sponsored Ads
    Ad


     

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact