Multiple choice

What will be the output of the following function?

include <stdio.h>

void main() { int a[5] = {5,1,15,20,25}; int i,j,m; i = ++a[1]; j = a[1]++; m = a[i++]; printf(“%d %d %d”,i,j,m); }

  1. 2 1 15

  2. 1 2 5

  3. 3 2 15

  4. 2 2 2

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

Initially, a[1] is 1. The line i = ++a[1] increments a[1] to 2 and sets i to 2. Then j = a[1]++ sets j to 2 and increments a[1] to 3. Finally, m = a[i++] assigns a[2](which is 15) to m and increments i to 3, resulting in 3 2 15.