Multiple choice technology programming languages

1)main() { int i = -1, j= -1, k=0, l=2, m; m=i++&&j++&&k++||l++; printf(“%d %d %d %d %d”,i,j,k,l,m); }

  1. -1 -1 0 2 0

  2. -1 -1 0 2 1

  3. 0 0 1 3 1

  4. 0 0 1 3 0

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

The expression m=i++&&j++&&k++||l++ uses short-circuit evaluation with post-increment. Starting: i=-1, j=-1, k=0, l=2. First i++ evaluates to -1 (true), then i becomes 0. Since -1 (true) && j++, we evaluate j++: j=-1 evaluates to -1 (true), then j becomes 0. Now we have (-1 && -1) which is 1 (true) && k++. But wait, i++ and j++ both happened. Now: i=0, j=0, k=0. Continuing: true && k++ means evaluate k++: k=0 evaluates to 0 (false), then k becomes 1. Short-circuit! Since k++ was false (0), the entire AND chain becomes false without needing more evaluation. m = (false) || l++, so we evaluate l++: l=2 evaluates to 2 (true), then l becomes 3. m = false || true = 1. Final values: i=0, j=0, k=1, l=3, m=1. This matches option C.