求教高手C 語言不定義結構體可以呼叫結構體指標

2021-09-01 05:17:48 字數 345 閱讀 1388

今天聽老師說專家級人物可以在c語言中定義乙個結構體不使用結構體指標,但是可以使用符號->且編譯器可以編譯通過。例如

struct stu

; 如果我們要訪問結構體內容,一般如下兩種方法:

struct stu p;

struct stu *p1;

定義結構體變數p,引用形式為:p.number=10;

定義指標變數p1、引用形式為:p1=(struct stu *)malloc(sizeof(struct stu));p1->number=20;

那麼有什麼方法,不定義指標,同時可以使用符號->,老師的意思大致是說可以p->number=30而編譯器可以通過。求解????

C語言結構體定義

c語言結構體定義在我看來類似資料庫的表 如 include include struct st1 int id char name 30 char int score int main struct st1 s1 s1.id 1 strcpy s1.name,張三 s1.m s1.score 90 ...

C語言 結構體 定義

c語言允許使用者自己建立由 不同型別資料組成的組合型資料結構 成為結構體。struct student 宣告結構體 一般形式 struct 結構體名 定義結構體變數 1先宣告結構體型別 在定義 struct student student1,student2 2宣告的同時定義變數 struct st...

C語言中 不定義結構體變數求成員大小

所謂的求成員大小,是求成員在該結構體中 用 sizeof 結構體名.結構體成員名 求來的.很多時候我們需要知道乙個結構體成員中的某個成員的大小,但是我們又不需要定義該結構體 型別的變數 定義的話會讓人難以理解,又沒有實際的作用,幹嘛要定義?考慮可以用指標來反求,比如有乙個 point 型別的指標 p...