Qualcomm Interview Question for Software Engineer / Developers






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

struct *ptr ;
int size = (char *)(ptr+1) - (char *)ptr ;

- mailshreyas March 11, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

you can use the sizeof function...

eg..for int: sizeof(int)
for char pointer: sizeof (char *)
for your own structure: sizeof (struct my_structure)

- woohoo February 27, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This has to do with padding. Structures are usually padded with extra bytes for proper memory alignment. Thus size(struct) does not return the exact size of struct. we need to declare a struct as __(Packed)__ and then do a size of operation. There might be a better way.

- Suman April 16, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

hi suman,
can you explain with small code

- sasi November 01, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

yes sum an is right and it has to do with padding and it will be multiples of 4 in modern computer.... but the way you order the data members may increase or decrease the size of structure based on padding needs. but it looks like sizeof will give you the size of structure but may be the interviewer needs this padding answer to make sure you have clear understanding


#pragma pack(push) /* push current alignment to stack */
#pragma pack(1) /* set alignment to 1 byte boundary */

struct data
{
char Data1;
long Data2;
char Data3;
};

#pragma pack(pop) /* restore original alignment from stack */

- Moorthi August 09, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

So we have 2 lists A and B and we need to sum them.
Question 1. The results is again a list?
->: let's assume yes, a SUM list
Question 2. How numbers are organized? starting from the most significant ? or least significant?
-> if from most significant on, the problem is hard, so we can just reverse the list and then sum. Reversing a list is a O(n) problem and the sum is also an O(n) so the total op is O(n).

So assuming A, B lists starting from the least significant digit and the sum returns S list also from the least sig. digit the problem is:

typedef struct list_t{ 
	int x;
	struct list_t* next;
	} list_t;
	
    
// add two lists and return a list
list_t* add(list_t* A, list_t *B){  
	int s;
	list_t* least=NULL; //pointer to the sum list least impotant digit
	list_t* most=NULL; //pointer to the sum list most impotant digit
	list_t* tmp=NULL;	
	               
	// while there are 2 digits, add them
	while( A != NULL && B != NULL){
		s = A->x + B->x;           
		// initialize sum list
		tmp = malloc(sizeof(list_t));
		if(least == NULL){
			least = most = tmp;
		}
		// add either 1 or 2 digits
		if(s<9){
			tmp->x = s;
			tmp->next = NULL;
			most->next=tmp;
			most=tmp;
		   }
		else{
			tmp->x = s -10;
			tmp->next = malloc(sizeof(list_t));
			tmp->next->x = 1;
			tmp->next->next=NULL;
			most->next=tmp;
			most=tmp->next;			
		}       	 
		A=A->next;   		
		B=B->next;
	}               
	while( A != NULL ){	
		most->next=malloc(sizeof(list_t));
		most->next->x = A->x;
		A = A->next;         
		most = most->next;		
	}
	while( B != NULL ){	
		most->next=malloc(sizeof(list_t));
		most->next->x = A->x;
		B = B->next;         
		most = most->next;		
	}
	return least;
}

- N568 January 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

typedef struct {
xxxxx;
} strName;
strName strArray[2];
int size = &strArray[1] - &strArray[0];

- gougou February 10, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think it should be:

int size = (char*)&strArray[1] - (char*)&strArray[0];

- foxele June 13, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#pragma pack(push, 1) /* set alignment to 1 byte*/
typedef struct StructSize
{
int a;
char b;
float c;
char aa;
char bb;
char cc;
char dd;
}structsize ;

#pragma pack(pop) /* set back to old alignment*/

structsize Size;
structsize *ptrSize;
ptrSize =&Size;
int Length= (char *)(ptrSize+1) - (char *)ptrSize;
/* here goes correct struct size*/

- Vijay Mukilan S June 17, 2013 | 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