i read in a book about c that post ++ has higher precedence than the unary dereference *.
if that's true then why in a loop like the follwoning
char *p, *q;
while ( *p++ = *q++);
*p++ isn't calculated as *(p++)?
Printable View
i read in a book about c that post ++ has higher precedence than the unary dereference *.
if that's true then why in a loop like the follwoning
char *p, *q;
while ( *p++ = *q++);
*p++ isn't calculated as *(p++)?
Good question, it shows that you've been paying attention. We like that. :) Think about it this way:
T val;
T *p;
...
val = *p++;
1) The postfix increment makes a copy of p
2) The real p is incremented
3) The copy is dereferenced
4) The result of the dereference is assigned to val
So the increment is performed first, but by implementation of definition, it appears as if the indirection comes first.
Thanx. Do you know any site or tutorial about precedence ?
Here's one: C Language Operator Precedence Chart.
[edit]
And here's an interesting article explaining that there is no such thing as operator precedence in C.
[/edit]