# ISRO | ISRO CS 2015 | Question 72

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]);
}
```

(A) 1 2 3 3 5 5 7 8
(B) 1 2 3 4 5 6 7 8
(C) 8 7 6 5 4 3 2 1
(D) 1 2 3 5 4 6 7 8

Explanation: Given array: ```for (i=2; i<6; ++i)
x[x[i]]=x[i];```
```For i = 2, x[x] = x
= x = 3  // since x = 3
For i = 3, x[x] = x
= x = 3  // since x = 3
For i = 4, x[x] = x
= x = 5  // since x = 5
For i = 5, x[x] = x
= x = 5  // since x = 5
Loop terminates at x = 6, so no changes in index 6 and 7.```

New array: Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Previous
Next