GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  GeekInterview.com  >  Tech FAQs  >  OOPS

 Print  |  
Question:  What is memset, and why it is used, When it is used?

Answer: I need a simple example progam for this with clear definition


August 08, 2007 05:53:32 #1
 Bharani   Member Since: Visitor    Total Comments: N/A 

RE: What is memset, and why it is used, When it is use...
 

Memset is used to set a buffer with a specific character
 for example
memset (dptr, 'A', 10); // sets the first 10 character to character 'A'

#include <memory.h>
#include <stdio.h>

int main( void )
{
   char buffer[] = "This is a test of the memset function";

   printf( "Before: %sn", buffer );
   memset( buffer, '*', 4 );
   printf( "After:  %sn", buffer );
}

Output
Before: This is a test of the memset function
After:  **** is a test of the memset function

     

 

Back To Question