Multiple choice technology programming languages

What will be the output of the following program : void main() { int a=1,b=2,c=3,d=4,e; e=(a,a)+(b,c)+(c,d)-(d,b); printf("%d", e); }

  1. Compile-Time Error

  2. 10

  3. 6

  4. 2

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Evaluate comma expressions left to right, returning rightmost value. (a,a) returns a=1. (b,c) returns c=3. (c,d) returns d=4. (d,b) returns b=2. So e = 1 + 3 + 4 - 2 = 6. Option A is wrong - no compile error. Option B would require different arithmetic. Option D is incorrect.