关键字是c语言设定好的,不可自己创建
auto 、break、case、char、 const、continue、default、do、double、else、enum、extern、float、for、goto、if、int、long、register、return、short、signed、sizeof、static、struct、switch、typeddef、union、unsigned、void、volatile、while
typedef---类型重命名
static---用来修饰变量和函数的,修饰全局、局部变量和函数。
对全局变量的修饰
#include<stdio.h>
void test()
//void是不让程序有返回值
{
int a = 1;
a++;
printf("%d\n", a);
}
int main()
{
int i = 0;
while (i < 10)
{
test();
i++;
}
return 0;
}
加上static后的结果
#include<stdio.h>
void test()
//void是不让程序有返回值
{
static int a = 1;
a++;
printf("%d\n", a);
}
int main()
{
int i = 0;
while (i < 10)
{
test();
i++;
}
return 0;
}
本质上,static改变了变量的存储位置,影响了变量的生命周期,和程序的生命周期一样长了。
将储存位置从栈区变到了静态区
对全局变量的修饰、
#include<stdio.h>
int a=20;
int main()
{
printf("%d", a);
return 0;
}
加上static后程序报错
原因是static使得全局变量的外部链接变成了内部链接,其他源文件就不能使用这个全局变量了。
对函数的修饰
#include<stdio.h>
int add (int x, int y)
{
return x + y;
}
int main()
{
int a = 10;
int b = 20;
int z = add (a, b);
printf("%d", z);
return 0;
}
#include<stdio.h>
static int add (int x, int y)
{
return x + y;
}
int main()
{
int a = 10;
int b = 20;
int z = add (a, b);
printf("%d", z);
return 0;
}
输出错误的原因是static将函数的外部链接变成了内部链接,其他源文件就不能使用这个全局变量了。
register-----寄存器
电脑的存储设备
寄存器
高速缓存
内存
硬盘
int main()
{
//寄存器变量
register int num=3;
//建议把3放在寄存中(放不放的进去还要看编译器本身)
return 0;
}