3 回答

TA貢獻(xiàn)1803條經(jīng)驗(yàn) 獲得超3個(gè)贊
檢查了程序,結(jié)果是,
p++; // use it then move to next int position
++p; // move to next int and then use it
++*p; // increments the value by 1 then use it
++(*p); // increments the value by 1 then use it
++*(p); // increments the value by 1 then use it
*p++; // use the value of p then moves to next position
(*p)++; // use the value of p then increment the value
*(p)++; // use the value of p then moves to next position
*++p; // moves to the next int location then use that value
*(++p); // moves to next location then use that value

TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超8個(gè)贊
關(guān)于“如何增加指針地址和指針的值?” 我認(rèn)為這++(*p++);實(shí)際上是定義明確的,并且可以滿足您的要求,例如:
#include <stdio.h>
int main() {
int a = 100;
int *p = &a;
printf("%p\n",(void*)p);
++(*p++);
printf("%p\n",(void*)p);
printf("%d\n",a);
return 0;
}
它不是在序列點(diǎn)之前兩次修改同一件事。我認(rèn)為對(duì)于大多數(shù)用途而言,這不是一個(gè)好風(fēng)格-對(duì)我來(lái)說(shuō)有點(diǎn)神秘。
- 3 回答
- 0 關(guān)注
- 721 瀏覽
添加回答
舉報(bào)