C語言複習 結構體指標與自增運算子

2021-06-03 12:54:55 字數 855 閱讀 5674

測試**:

#include

#include

int main() ;

struct student st = ;

struct student *ptr = &st;

printf("ptr->name = %s\n", ptr->name);

printf("*ptr->name = %c\n", *ptr->name);

printf("*ptr->name++ = %c\n", *ptr->name++);

printf("*ptr->name = %c\n", *ptr->name);

printf("ptr->score = %d\n", ptr->score);

printf("ptr->score++ = %d\n", ptr->score++);

printf("ptr->score = %d\n", ptr->score);

return 0;

}=== 執行結果:

ptr->name = brian

*ptr->name = b

*ptr->name++ = b

*ptr->name = r

ptr->score = 97

ptr->score++ = 97

ptr->score = 98

=== 分析:

1. ptr->name,這個不說了。

3. *ptr->name++,由於*和++的優先順序相同,而且結合性是由右至左,所以相當於: *((ptr->name)++),即獲取首位址字元後,將name指標右移一位。(當前列印還是首位址的值)

4. *ptr->name,此處為驗證上一步的指標位置。

C語言複習 指標自增 自減以及

當指標 自增 或者自減 運算子,以及 這三個 運算子在同乙個語句時,要注意 的作用點在 測試 include int main int p i printf d n p printf p d n p printf d n p printf p d n p printf d n p printf p ...

C語言複習 自引用結構體

測試 include include int main struct student p,q,r,current p struct student malloc sizeof struct student q struct student malloc sizeof struct student r...

C語言指標與自增詳解

在初學c語言,接觸指標的時候,真的是比較迷惑的一件事,恰巧指標還和自增運算子碰到一起了,更是碰出了無限的可能,正所謂兩儀生四象,四象生八卦啊 為了期末考試,徹底弄明白指標和自增運算子在一起時的各種可能和現象,我們可以直接通過編寫c 來試驗一下 先上結論 p 先傳值,後值自增1,模擬a p p 先傳值...