Microsoft Interview Question for Software Engineer / Developers


Country: India
Interview Type: Written Test




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

In each of the three lines, a variable (i or j) is referenced more than once. As there are no sequence points in between such instructions, the behavior is undefined.

Read this for further clarification about Sequence points in C/C++: c-faq.com/expr/seqpoints.html

- Monish October 14, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The evaluation happens from Right to left for the statement 2 and 3. Hence the result is 9 for both. Not 8 as mentioned by you.

- Rajan.Munuswamy October 07, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@rajan
THe output for 3 statement is 8 and not 9. I ran it on codepad

- Swap October 07, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This code causes undefined behavior (so what will happen can be compiler-specific)

- eugene.yarovoi October 09, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

yes the ans would be 8 if you remove the 3rd comment..
first the value of i will be incremented (as it is pre increment)then
i=10-10+4+4 wud be evaluated and finally the post increment operation(j++)takes place twice

- shivani October 09, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

after evaluating 3rd statement post increment operation should take place for i too. so it should result in 9 then how 8?

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

Tried both 2 and 3. Both results are 8 as per VS C++.

- Sidh October 25, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

1st comment gives 0
2nd comment gives 3
3rd comment gives 9

- abc October 27, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This one is correct

- Anonymous November 04, 2011 | Flag


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