結構體定義的問題

2021-10-04 02:57:13 字數 581 閱讀 7397

在定義結構體的時候遇到了問題。

之前自己習慣這樣去宣告變數:

typedef struct student;
student stu[100];

這裡其實student是結構體的型別,還不是變數,真正的變數是stu,加typedef 為型別取了乙個別名為student。

如果不用typedef,定義為:

struct student;
那麼定義變數的時候就要:struct student stu[100];

還有一種比較好的寫法:型別和變數都在一開始就定義了:

struct student stu[100];
這樣定義的也是乙個結構體陣列變數,但是重新定義結構體變數時候也要寫完整。.

eg:struct student stu1;

還有一種錯誤寫法:

typedef struct student stu[100];```

這裡stu依然是乙個結構體型別,並不是變數

資料結構結構體定義問題

typedef 用法 解釋typedef unsigned int uint uint等價於unsigned int型別定義 typedef int pointer pointer p宣告等價於int p宣告 在資料結構中,經常用typedef定義結構體 typedef struct treenod...

結構體的定義

關於c語言中結構體的幾種定義方式和它們之間的不同。1 先定義結構體型別,再定義結構體型別變數 struct 結構體名稱 struct 結構體名稱 結構體變數1,結構體變數2 struct 結構體名稱 結構體變數3,結構體變數4 用此結構體型別,可以定義更多的該結構體型別變數。2 定義結構體型別同時定...

結構體的定義

在c語言中,結構體 struct 指的是一種資料結構,是c語言中聚合資料型別 aggregate data type 的一類。結構體可以被宣告為變數 指標或陣列等,用以實現較複雜的資料結構。結構體同時也是一些元素的集合,這些元素稱為結構體的成員 member 且這些成員可以為不同的型別,成員一般用名...