1.关键字 typedef
typedef 顾名思义是类型定义,这里应该理解为类型重命名。
typedef unsigned int u; //unsigned是C语言的关键字,表示无符号数。
//typedef把unsigned int 重命名为u。
int main()
{
u a = 1;
printf("%d", a);
return 0;
}
2.关键字static
在C语言中: static是用来修饰变量和函数的。
(1) 修饰局部变量-称为静态局部变量。
(2)修饰全局变量-称为静态全局变量。
(3)修饰函数-称为静态函数。
2.1 修饰局部变量
未修饰局部变量:
void test()
{
int i = 0;
i++;
printf("%d", i);
}
int main()
{
int i = 0;
while (i <= 10)
{
i++;
test();
}
return 0;
}
运行结果:
修饰局部变量:
void test()
{
static int i = 0; //static修饰局部变量,改变了局部变量的生命周期(本质上是改变了变量的存储类型)
i++;
printf("%d", i);
}
int main()
{
int i = 0;
while (i <= 10)
{
i++;
test();
}
return 0;
}
运行结果:
2.2 修饰局部变量
static未修饰使用全局变量。
static修饰使用全局变量。
全局变量:在其他源文件内部可以被使用,是因为全局变量具有外部链接属性
但被static修饰之后,就变成了内部链接属性,其他源文件就不能链接到这个静态的全局变量了!
2. 3修饰函数
static修饰外部函数和修饰全局变量同理。