r**c 发帖数: 30 | 1 why *d is evaluate first then ++? In the precedence table it shows ++ (
postfix) is higher than dereference. |
z******g 发帖数: 271 | 2 It's easy to confuse operator precedence with order of evaluation. Operator
precedence only decides how operators match with operands, not the order
they are evaluated.
You are correct that the precedence of postfix is higher than dereference.
But that only tells you *d++ should be *(d++) but not (*d)++. This does not
conflict with the fact that postfix is evaluated after the statement.
Hope that helps. |
r**c 发帖数: 30 | 3 So this means it's equivalent to
*d = *s;
d++;
s++;
right? |
z******g 发帖数: 271 | |
r**c 发帖数: 30 | 5 Thanks! Yesterday I had a phone interview with Google.
The interviewer thought it's wrong to use *d++ = *s++ to do copy as ++ will
happen before *. Shall I find a way to tell him? (via recruiter). Will
that have any influence on his decision? |
p***y 发帖数: 637 | 6 这代码风格不好啊。表达式有副作用,而且是容易弄错的副作用。多写一两行少很多歧
义。
will
【在 r**c 的大作中提到】 : Thanks! Yesterday I had a phone interview with Google. : The interviewer thought it's wrong to use *d++ = *s++ to do copy as ++ will : happen before *. Shall I find a way to tell him? (via recruiter). Will : that have any influence on his decision?
|
N*D 发帖数: 3641 | |
s**x 发帖数: 7506 | 8 面试千万不要写这种code.
To me, this is only used in the famous string Copy:
While ( *d++=*s++); |