Interview Question


Country: India




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

m = ++i&& ++j || ++k;
in this case first value of 'i' is incremented , so it become 0 . in AND binary operation if one value is zero then there is no need to check other value , so we dont increment value of 'j' or say we do not bother about 'j' .so value of 'j' is still 2.
in this expression OR is also there so we have to value of k, so we increment value of 'k', that will now 1.
after all expression become true so value of 'm' is 1.
so final out put is 0 2 1 1

- Gupta July 21, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
2
of 2 vote

and note that AND operator priority is higher than OR operator priority

- anthrax512 July 21, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

for ny doubt learn short circuit property of AND ,OR operator.

- zeroByzero July 21, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

{
i have a doubt...
Unary operator have higher precedence over logical operator.So all unary operator should process first and should produce following output 0311
Please explain where i m wrong
}

- achillesh July 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

{
i have a doubt...
Unary operator have higher precedence over logical operator.So all unary operator should process first and should produce following output 0311
Please explain where i m wrong
}

- achillesh July 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

{
according to c standards &&,|| are sequence points. So, ++i,++j and ++k are treated as separate expressions.Hence all the unary operators are not processed first.
}

- chaitanya August 01, 2014 | 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