1、auto
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
//常见关键字
int main()
{
{
int a = 0;//自动创建的,自动销毁的,自动变量
//auto自动省略
//在新的C语言中也有其他用法,暂时不考虑
}
return 0;
}
//auto 是自动的 每个局部变量都是auto的修饰的
//extern 是用来申明外部符号
//regtster 寄存器关键字
//signed 有符号的
//unsigned 无符号的
//static 静态的
//union 联合体(共用体)
//void 无,空
2、static
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
//typedef unsigned int u_int//类型重新定义
//int main()
//{
// unsigned int a = 100;
// u_int a = 100;
// //两端代码完全一样
// return 0;
//}
//static-静态的 三个用法
//1.修饰局部变量 改变了局部变量的生命周期(本质上改变了变量的存储类型)
//栈区:局部变量、函数参数
//堆区:动态内存分配的
//静态区:全局变量、static修饰的、静态变量
//
//2.修饰全局变量
//3.修饰函数
//
//
//void test()
//{
// static int a = 1;//当没有static时输出2 2 2 2 2 2 2 2 2 2
// //当static修饰int a = 1 时 输出2 3 4 5 6 7 8 9 10 11
// a++;
// printf("%d ", a);
//}
//
//int main()
//{
// int i = 0;
// while (i < 10)
// {
// test();
// i++;
// }
// return 0;
//}
static修饰全局变量,使得这个全局变量只能在自己所在的源文件(.c)内部使用,其他源文件不能使用
当使用其他源文件内的全局变量时,必须使用extern 声明外部符号
static修饰函数和修饰全局变量功能类似