C Quiz – 103 | Question 2
What’s going to happen when we compile and run the following C program snippet?
#include "stdio.h" int main() { int a = 10; int b = 15; printf("=%d",(a+1),(b=a+2)); printf(" %d=",b); return 0; } |
chevron_right
filter_none
(A) =11 15=
(B) =11 12=
(C) Compiler Error due to (b=a+2) in the first printf().
(D) No compile error but output would be =11 X= where X would depend on compiler implementation.
Answer: (B)
Explanation: As per C standard C11, all the arguments of printf() are evaluated irrespective of whether they get printed or not. That’s why (b=a+2) would also be evaluated and value of b would be 12 after first printf(). That’s why correct answer is B.
Quiz of this Question
Recommended Posts:
- C Quiz - 101 | Question 4
- C Quiz - 110 | Question 2
- C Quiz - 106 | Question 3
- C Quiz - 106 | Question 4
- C Quiz - 106 | Question 5
- C Quiz - 107 | Question 1
- C Quiz - 107 | Question 2
- C Quiz - 107 | Question 3
- C Quiz - 107 | Question 4
- C Quiz - 101 | Question 5
- C Quiz - 104 | Question 1
- C Quiz - 102 | Question 1
- C Quiz - 102 | Question 2
- C Quiz - 102 | Question 3
- C Quiz - 106 | Question 2



