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++)?
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.
My best code is written with the delete key.
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]
Last edited by Dave_Sinkula; 05-22-2003 at 04:04 PM.
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*