Qualcomm Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
0
of 0 vote

Basic first version - copies one byte at a time.

void memcpy(void* src, void* dst, size_t len)
{
char* p = (char*)src;
char* q = (char*)dst;
while(len--)
*p++ = *q++;
}

Version 2 - copies int at a time - better performance.

void memcpy(void* src, void* dst, size_t len)
{
/* Copy whatever can be copied as integers */

size_t nTimes = len/sizeof(int);
int* pIntSrc = (int*) src;
int* pIntDst = (int*) dst;

while( nTimes-- )
*pIntSrc++ = *pIntDst++;

/* copy the remainder */
nTimes = len % sizeof(int);
char* pCharSrc = (char*) pIntSrc;
char* pCharDst = (char*) pIntDst;

while( nTimes-- )
*pCharSrc++ = *pCharDst++;

/* Done */
}

- Girish September 09, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

what about memory alignment check while accessing lets say 4 bytes for int? the src and dest pointer should be only copied as int if they are aligned on the same boundary. For your solution assumption is that processor allows unaligned memory accesses which will make you better performance version bad

- kar November 15, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

int memcpy(void* dest,const void* src,int num)
{
while(num--)
*(char*)dest=*(char*)src;
dest=(char*)dest+1;
src=(char*)src+1;
}

- Jackie September 09, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

what about overlap checking ?

- jay99 January 12, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

instead of (int *) typecase use (long *) and take care for remaining bytes
take care for over lapping

- mlakshmanarao August 04, 2011 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More