Take FREE!! Online Mettl Mock Test to Crack TechM and Other Companies Written Exams.
Get Off-Campus Placement Jobs Info !!!
TCS NQT Technical and Managerial Round Interview Questions
Interview Questions and Answers :: Broadcom Ltd

37. Write a code to implement memcpy.

Answer:

The memcpy function is used to copy a block of data from a source address to a destination address. The prototype for memcpy is

void * memcpy(void * destination, const void * source, size_t num);

#include
#include

void myMemCpy(void *dest, void *src, size_t n)
{
// Typecast src and dest addresses to (char *)
char *csrc = (char *)src;
char *cdest = (char *)dest;

// Copy contents of src[] to dest[]
for (int i=0; i cdest[i] = csrc[i];
}

int main()
{
char csrc[] = "broadcom interview";
char cdest[100];
myMemCpy(cdest, csrc, strlen(csrc)+1);
printf("Copied string is %s", cdest);
return 0;
}

Post Your Answer Here:      Public      Private

Rate This: +0 -0
Report     

Post Your Reply Here:     

Report Error

Report Error

Please Login First Click Here