Q37
What will be the output of the following program? void main() int a, b, c, d; a = 3; b = 5; c = a, b; d = (a, b); printf("c=%d d=%d", c, d);
A.
c=3 d=3
B.
c=3 d=5
AnswerC.
c=5 d=3
D.
c=5 d=5
Answer: Option B
Solution
Answer: Option B
Solution:
The comma operator evaluates both of its operands and produces the value of the second. It also has lower precedence than assignment. Hence c = a, b is equivalent to c = a, while d = (a, b) is equivalent to d = b.