解引用和后缀的precedence [英] Precedence of dereference and postfix
问题描述
当我用K&放阅读TCPL; R,我只是不明白两位前pressions:
When I read the TCPL by K&R, I just couldn't understand two expressions:
*p++ = val; /*push val onto stack */
下面是我的想法:
-
解引用和后缀具有相同的precedence,和结合性是从右到左,所以
dereference and postfix has the same precedence, and associativity is right to left,so
* P ++ = VAL
可能与相同*(P +)= VAL
,因为指针通常是下一个位置的顶部,所以在这个code,首先,因为括号的对增加1,所以p是两个单位以上的当前顶部,但不是一个单位以上的当前顶部,其中VAL应! THX
*p++ = val
maybe the same with *(p++) = val
, because the pointer usually is the next position to the top , so in this code, p increase 1 first because of the parenthesis, so the p is the two units above the current top ,but not the one unit above the current top ,where the val should be!!! Thx
推荐答案
在preFIX递增/递减和间接引用运营商都是平等的precedence,但后缀运算符更高,所以 * p ++
相同 *(p ++)
,这就像写 * p = VAL; p ++;
The prefix increment/decrement and dereference operators are equal precedence, but the postfix operator is higher, so *p++
is the same as *(p++)
, which is like writing *p = val; p++;
如果你写(* P)++ = VAL
,它不会编译,因为你会试图分配一个值到一个数字。
If you wrote (*p)++ = val
, it wouldn't compile, as you'd be trying to assign a value to a number.
这篇关于解引用和后缀的precedence的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!