我学习存储类中C.I有一个简单的代码静态局部变量函数
enter code here
int f1()
{
static int i=0;
i++;
printf("%d",i);
}
int f2()
{
printf("%d",i);
}
int main()
{
f1();f2();f1();f2();
}
编译器会发出错误为“我”在F2为未申报的()。 正如我所想,内存静态变量分配在程序内存的数据部分。因此该文件中的任何功能都应该能够访问它。
编译器如何知道在函数中本地声明的变量是仅限于该函数?编译器如何评估它?
http://stackoverflow.com/questions/6223355/static-variables-in-class-methods可能的答案 –