Examveda
Examveda

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

C. c=5 d=3

D. c=5 d=5

Answer: Option B

Solution(By Examveda Team)

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.


This Question Belongs to C Program >> Operators And Expressions

Join The Discussion

Comments ( 1 )

  1. Hemanth Tunuguntla
    Hemanth Tunuguntla :
    7 years ago

    Can you please give me the explanation in breifly as compared with the above mentioned answer

Related Questions on Operators and Expressions