posted 14 years ago
hi,
the critical thing to notice here is that
'i' is used to hold the value in the array
and also to index through the array.
Hence,
when we go step by step into the for loop, its as follows:
arr = {1,2,3,4}
loop(1)
i = 1 , arr[1] = 0 // i takes first value of the array arr
arr = {1,0,3,4}
loop(2)
i = 0, arr[0] = 0 // i takes second value of the array arr
arr = {0,0,3,4}
loop(3)
i = 3 , arr[3] = 0 // i takes third value of the array arr
arr = {0,0,3,0}
loop(4)
i = 0 , arr[0] = 0 // i takes fourth value of the array arr
arr = {0,0,3,0}
confusing...
but observe things step by step and it will be clear.