Programming-for-Output-Problems
October 6, 2023Programming-for-Output-Problems
October 6, 2023Programming-for-Output-Problems
Question 22 |
The output of the following program is
main()
{
static int x[] = {1,2,3,4,5,6,7,8}
int i;
for (i=2; i<6; ++i)
x[x[i]]=x[i];
for (i=0; i<8; ++i)
printf(“%d”, x[i]);
}
main()
{
static int x[] = {1,2,3,4,5,6,7,8}
int i;
for (i=2; i<6; ++i)
x[x[i]]=x[i];
for (i=0; i<8; ++i)
printf(“%d”, x[i]);
}
1 2 3 3 5 5 7 8 | |
1 2 3 4 5 6 7 8 | |
8 7 6 5 4 3 2 1 | |
1 2 3 5 4 6 7 8 |
Question 22 Explanation:
For loop will execute for the i value 2,3,4,5
For i = 2, x[x[2]] = x[2]
= x[3] = 3 // since x[2] = 3
The array elements representation are
Correct Answer: A
Question 22 Explanation:
For loop will execute for the i value 2,3,4,5
For i = 2, x[x[2]] = x[2]
= x[3] = 3 // since x[2] = 3
The array elements representation are
Subscribe
Login
0 Comments