🎴 Flashcard Mode

Programming (C/C++)

Card1 / 30
Mastered0
Review0
QuestionClick to flip

<span style="font-size:10.0pt;font-family:Arial;mso-fareast-font-family:"Times" new="" roman";mso-bidi-font-family:arial;color:black;mso-ansi-language:en-us;mso-fareast-language:en-us;mso-bidi-language:ar-sa="">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);
}

AnswerClick to flip back
A
3 2 15
💡 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.

Change Mode