fred rosenberger wrote:I think your question basically boils down to:
Why does this not work:
remember that "++i" CHANGES the value of i. so each time through this loop, you change i twice - once on the assignment line, and once each time you restart the loop.>
fine it is changing twice, consider first iteration for i=0, then
elements[0]=elements[1];//as preincrement operator is present i value present in right side will be 1
then for 2nd iteration i due to for loop will be 1, then it will be
elements[1]=elements[2]// i value will be 2 due to pre increament operater.
then for 3rd iteration i will be 2
elements[1]=elements[3];// same here also
same thing is happening when we use i+1 instead of ++i. but i+1 is giving correct output. y? am i missing anything. did i go wrong somewhere?