Array[i] = i++; [duplicate]
int main()
{
int arr[5]= {55}, i=0;
while (i<5)
{
arr[i]= i++;
}
for(i=0; i<5; i++)
printf("%d, ", arr[i]);
return 0;
}
why is the output ( 55,0,1,2,3) Not ( 0,1,2,3,4)
Ps: I'm using GCC compiler
Solution 1:
This is undefined behavior.
Clang actually warns about it
warning: unsequenced modification and access to 'i' [-Wunsequenced]
arr[i]= i++;
~ ^