can someone provide me more insight on why this code works the way it works
#include <stdio.h>
int main()
{
int a[5] = {1,2,3,4,5};
int i;
for(i=0;i<5;i++)
{
printf("%d,%d \n",i[a],i[a]++);
}
return 0;
}
The result is
2,1
3,2
4,3
5,4
6,5
Thanks
The behavior is undefined.
N1256 6.5p2:
The program both modifies
i[a](ini[a]++) and reads its value (in the next argument), and the result of reading the value is not used to determine the value to be stored.This is not just a matter of the unspecified order of evaluation of function arguments; the fact that there’s no sequence point between
i[a]++andi[a](since that’s not a comma operator) means that the behavior, not just the result, is undefined.