Practice mode C Language

What is printed by this C code: int i = 0; int r = i++ || i++; printf(“%d %d”, r, i);?

Correct answer A. 1 2

Explanation

|| has a sequence point after its left operand. The first i++ yields 0 (false) and makes i 1, so the right operand must be evaluated: it yields 1 (true) and makes i 2. The whole expression is therefore 1. Short-circuiting would skip the right side only if the left were true, which is why 1 1 is wrong. The sequence point also makes this code well defined.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.