作用域
函数、类、块、文件、其他
静态生存期
static 默认值是0
动态生存期
不会在全局区小于静态区
#include <iostream>
using namespace std;
int i=1;
void other() {
static int a = 2;
static int b;
int c = 10;
a += 2;
i += 32;
c += 5;
cout << i << ";" << a << ";" << b << ";" << c << ";" << endl;
b = a;
}
int main() {
static int a;
int b=-10;
int c = 0;
cout << i << ";" << a << ";" << b << ";" << c << ";" << endl;
c += 8;
other();
cout << i << ";" << a << ";" << b << ";" << c << ";" << endl;
i += 10;
other();
return 0;
}
结果:
1;0;-10;0;
33;4;0;15;
33;0;-10;8;
75;6;4;15;
请按任意键继续. . .