+ 1
Why results in this code is 3,2,5,5?
2 Respuestas
+ 3
When i is 0
x[0] = x[0+1]
=x[1]
=3
so first element becomes 3
Then, when i is 1,
x[1] = x[1+1]
=x[2]
=2
so second element becomes 2
Similarly, when i is 2,
x[2] = x[2+1]
=x[3]
=5
so third element becomes 5
condition is i < length - 1
length is 4
length - 1 is 3
so max is 2
so for loop ends
so fourth element remains unchanged
+ 2
Thanks a lot. I understand now.