Qualcomm Interview Question for Software Engineer / Developers






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

The reason is when you do pointer subtraction it gives you the no of positions/elements by/in which the two pointers differ. Rather than giving the mathematical differnce (which someone can think to be 4 for the first case.)

- 123 February 15, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Perfect!

- csk April 01, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

does compiler do some optimization first on p+1-p?

- isisme March 05, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

judging from the assembly code the compiler spits out, it does optimization on p+1-p.
both statements essentially becomes equivalent to printf("%d", 1)

- anon March 31, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The constant expressions are evaluated at compile time in C. The expressions in printf statements are constant expressions.

- ab April 13, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

If four was expected, then the first print statement would need to be like:
printf("%d\n", (int) ( (char*)(p+1) - (char*)p ) );

Judging from the code and question, it seems like the desired result was to print out the size of int and char.

- Anonymous August 24, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think you are right

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

compile and run it:
--->1st: 1
--->2nd: 1

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

Did you set the address of those pointers?

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

even with this:
int *p,*p11,pp[]={11,22,33};
char *q,*q11,*qq="qqq";
p=pp;
q=qq;
printf("--->1st: %d\n",p+1-p);
printf("--->2nd: %d\n",q+1-q);

p11=p+1;
q11=q+1;
printf("--->1st: %d\n",p11-p);
printf("--->2nd: %d\n",q11-q);

p11=pp;
q11=qq;
p11++;
q11++;
printf("--->1st: %d\n",p11-pp);
printf("--->2nd: %d\n",q11-qq);

--->1st: 1
--->2nd: 1
--->1st: 1
--->2nd: 1
--->1st: 1
--->2nd: 1

- Anonymous October 28, 2010 | 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