[Updated] Goldman Sachs Aptitude Test Questions and Answers
Practice List of TCS Digital Coding Questions !!!
Take 50+ FREE!! Online Data Interpretation Mock test to crack any Exams.
Interview Questions and Answers :: Broadcom Ltd

10. 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