天天看点

static 指针 结构体使用

static 指针 结构体使用

  • 1. static使用注意事项
static -->	//1.修饰局部变量:将变量的生命周期变为和整个程序相同 但是不改变作用域
			//2.修饰全局变量:将改变作用域为当前文件
			//3.修饰一个函数:修改了函数的作用域为当前文件
           
  • 2. 指针定义
printf("%p",p);	// %p --> 打印指针变量

int* p;			// int* 中的 * 和int构成一个整体-指针型变量
				// 一个指针变量占用 4 个字节,地址内的变量具体占用几个字节由 * 前面的类型决定
printf("%d",*p);	// *p 中的 * 代表"解引用"  台湾叫"提领"
           
  • 3. 结构体定义
//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;
	}