typedef struct students {
long code;
char *name;
float score[3];
float sum;
} cla[40];
這行代碼做了兩件事:
struct students。cla,它代表 「包含 40 個 struct students 的數組」。// 1. 先定義結構體類型
typedef struct students {
long code;
char *name;
float score[3];
float sum;
} Student;
// 2. 再定義數組類型別名(可選)
typedef Student ClassArray[40]; // ClassArray 代表 Student[40]
// 使用
ClassArray class1; // 等價於 Student class1[40];
Student class2[40]; // 直接定義數組,更直觀
cla 而非 Student[40]。typedef struct { ... } Student; 定義單個對象類型。Student classList[40]; 或 vector(C++)。typedef Student ClassArray[40]; 並加註釋。