static 指針 結構體使用
static --> //1.修飾局部變量:将變量的生命周期變為和整個程式相同 但是不改變作用域
//2.修飾全局變量:将改變作用域為目前檔案
//3.修飾一個函數:修改了函數的作用域為目前檔案
printf("%p",p); // %p --> 列印指針變量
int* p; // int* 中的 * 和int構成一個整體-指針型變量
// 一個指針變量占用 4 個位元組,位址内的變量具體占用幾個位元組由 * 前面的類型決定
printf("%d",*p); // *p 中的 * 代表"解引用" 台灣叫"提領"
//1、定義一個結構體
struct Student {
char name[20];
int score;
};
//将結構體 struct Student 給與新的名字 Stu
typedef struct Student Stu;
int main(){
Stu student;
//或者:struct Student student;
//struct Student 相當于 Stu
student.score = 100;
}
//2、定義結構體的同時,順便定義了一個結構體變量 student
// 可以再次用 struct Student 或者 Stu 定義新的變量
struct Student {
char name[20];
int score;
} student;
typedef struct Student Stu;
int main(){
student.score = 100;
}
//3、定義結構體的同時,順便将結構體 struct Student 給與新的名字 Stu
typedef struct Student {
char name[20];
int score;
} Stu;
int main(){
Stu student;
//或者:struct Student student;
//struct Student 相當于 Stu
student.score = 100;
}