It "works," just not the way you're expecting it to. The portion with the increment operator is evaluated first and it returns a value. The value will either be the value of 'i' before the incrementation or the value after the incrementation.
In this case, you've chosen pre-incrementation, which increments the value of a variable and returns the resulting incremented value.
So, using this line "array=array[++i]", the left side and right side are always accessing the same position in the array.
If 'i' is 3:
++i increments i to 4, and then returns 4 so
array[4]=array[4];
If you were to use the post-increment operator, it would look like this:
If 'i' is 3:
i++ increments i to 4, and then returns 3 so
array[4]=array[3];
Notice that neither case will perform the same way as your initial code block that uses "array=array[i+1];".
The functional equivalent of your initial code block would be this:
array[6] = { 1, 2, 3, 4, 5, 6 };
for(i=0; i < 6; 1)
{
array[i++]=array;
}
In that case, if 'i' is 3:
++i increments i to 4 and returns 3 so
array[3]=array[4];