*x++ makes num[3] equal to 5. x still points to num[3].
It seems I was wrong about this. I had assumed that x would get dereferenced first, but it seems that C's order of operations work differently than I thought they did.
I believe that this is the same program you wrote, except when written this way it is easier to see what is happening (and with the added print):
Code:
#include <stdio.h>
int main(void) {
int num[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int *p = &num[0];
int *q = &num[9];
int temp;
while (p < q) {
temp = *p;
*p = *q;
p++;
*p;
*q = temp;
q--;
*q;
printf("p = %p\nq = %p\ntemp = %d\n*p = %d\n*q = %d\n", p, q, temp, *p, *q);
printf("%s", "num values: ");
for (int i = 0; i < 10; ++i) {
printf("%3d", num[i]);
}
puts("\n");
}
}
To simplify it, you could just delete the dereferencing statements. It would make more sense then. C's order of operations basically makes them do nothing when combined with a post increment operator.