I am a little bit confused about pointer index operator in C. I will try to explain my question with an example:
int array[5] = {1,2,3,4,5};
int *p;
p = array;
p[2]++;
In the fourth line, I know that it increments the second index of array. However, when I see an index operator, I convert it.
For instance, I converted p[2]++ to *(p+2)++. According to the operator precedence table, in the statement of *(p+2)++, the increment and dereferencing operators have the same precedence, but increment takes precedence due to right associativity. Therefore, it becomes *(p+3). Then, this statement cannot change any value and just points third index of array.
Why does p[2]++ increment the second index of the array? What is wrong in my perspective?