变量作用域与生命周期

作用域

限定变量的使用范围

1
2
3
4
5
6
7
8
9
10
11
#include <stdio.h>
int main()
{
int a = 10;
{
int a = 11 ; \\作用域在{}内
}
printf("%d",a);
return 0
}

生命周期

变量:从创建到销毁的时间段

局部变量:进入局部范围开始,出局部范围结束f

全局变量:从程序开始到程序结束

extern

使用同一工程下的变量