Q.The program fragment int a = 5, b = 2; printf ("%d", a ++ + ++ b);
Correct answer: prints 8
Explanation
In given program fragment, the expression 'a++ + ++b' is evaluated as a+(++b) due to the precedence of the increment operator ++. The first '++' is the pre-increment operator applied to b, so b becomes 3. Then, the expression becomes a + 3, where a is 5. Thus, the output is 5 + 3 = 8 So, the correct answer is option (b) prints 8.
In given program fragment, the expression 'a++ + ++b' is evaluated as a+(++b) due to the precedence of the increment operator ++. The first '++' is the pre-increment operator applied to b, so b becomes 3. Then, the expression becomes a + 3, where a is 5. Thus, the output is 5 + 3 = 8 So, the correct answer is option (b) prints 8.