Question discussion

What is the output of the code written in C?

5191Medium DSSSB TGT Computer Science 0 replies 0 views
0
What is the output of the code written in C?
void main()
{
    int k, v;
    k = (v = 20, v + 2);
    printf("%d", k);
}
  • A2
  • BError
  • C20
  • D22
Correct answer: D

Explanation

The comma operator evaluates v = 20 first, then v + 2 = 22 is assigned to k, so it prints 22.

Discussion 0

Nobody has replied yet. Start the discussion!