Qualcomm Interview Question for Software Engineer / Developers






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

shorter code

void * round_32()
{
char * ptr = new char[some_num];
if(ptr & 0x1F)
{
ptr =(char*) ((int)ptr+(32-((int)ptr%32)));
}
return ptr;
}

====
this is a good one~ thanks

- Anonymous October 01, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I am not sure about this because it returns the auto variable in the function. and it would make memory leaking because it moves the pointer. How can it be released by free or something?

- Anonymous November 02, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

make alignment = 32

void * aligned_malloc(size_t bytes, size_t alignment)
{
char *ptr,*aptr;
size_t mask= ~(alignment-1);

if( ( (alignment%2) != 0 ) || (alignment==0))
{
printf("Must be power of 2");
exit(0);
}

ptr=(char *)malloc(bytes+alignment+sizeof(size_t)) ;
//allocate memory bytes + potential wastage due to alignment + storage

if (!ptr)
return NULL;

aptr = (char*)(((size_t)(ptr + sizeof(size_t)) & mask) + alignment);
/*find the next alignment boundary, which is the final pointer we will return
_______________________________________
ptr temp aptr
_______________________________________ */

char *temp = aptr - sizeof(size_t);
//Calculated the location where the actual pointer information will be stored
*((int*)temp) = (int) ptr;

printf("Pointer assigned by malloc %x\n",ptr);
printf("Pointer we return %x\n",aptr);

return aptr;
}

- Anonymous November 06, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

shorter code

void * round_32()
{
char * ptr = new char[some_num];
if(ptr & 0x1F)
{
ptr =(char*) ((int)ptr+(32-((int)ptr%32)));
}
return ptr;
}

- Anonymous May 26, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

{
//allocate enough memory, i.e. required memory + 32
void *mem = malloc(mem_required + 32);
//find 32 byte aligned address and store it in ptr
void *ptr = ((char *)mem + 32) & ~ 0x1F;

}

- Anonymous July 30, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote
{{{ ptr=malloc(size); while(ptr&0x1F) { {{{ free (ptr);}}} {{{ ptr=malloc(size);}}} }; }}} - Anonymous October 05, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

ptr=malloc(size);
while(ptr&0x1F)
{
free(ptr);
ptr=malloc(size);
}

- Anonymous October 05, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void * round_32()
{
void * mem_addr = malloc(1024);
void * align_32Byte_addr = mem_addr;
if(mem_addr & 0x1f)
{
align_32Byte_addr = (((uintptr_t)mem+32) & ~ ((uintptr_t)0x1F));
}
free (mem_addr);
return align_32Byte_addr;
}

- Anonymous February 10, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void * round_32()
{
	void * mem_addr = malloc(1024);
	void * align_32Byte_addr = mem_addr;
	if(mem_addr & 0x1f)
	{
		align_32Byte_addr = (((uintptr_t)mem+32) & ~ ((uintptr_t)0x1F));
	}
	free (mem_addr);
	return align_32Byte_addr;	
}

- Anonymous February 10, 2017 | 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