#include<iostream>
using namespace std;
void test();
int m()
{
int cout;
for(cout=1;cout<=5;cout++)
test();
return 0;
}
void test()
{
static int x=0;
int y=10;
x=x+2;
y=y+1;
cout<<"Inside test x="<<x<<" and y="<<y<<endl;
}
执行后的结果:
你对了吗?
抓住两点:
1、在快入口处分配内存,块出口释放内存的变量称为自动变量
2、在程序执行时一直保留内存分配的变量称为静态变量