Vidyalelo
C Programming · Q37

Operators and Expressions

Programming · C Programming · question 37

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
Answer
C.
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.