202002XX-变量的作用域
-
#include "stdafx.h"
-
#include "iostream"
-
#include "cstring"
-
#include "string"
-
void oil(int x);
-
using namespace std;
-
int main()
-
{ int texas=31;
-
int year=2011;
-
cout<<"in main,texas="<<texas<<",&texas="<<&texas<<endl;
-
cout<<"in main,year="<<year<<",&year="<<&year<<endl;
-
oil(texas);
-
cout<<"back to main,texas="<<texas<<",&texas="<<&texas<<endl;
-
cout<<"back to main,year="<<year<<",&year="<<&year<<endl;
-
return 0;
-
}
-
void oil(int x)
-
{
-
int texas=5;
-
cout<<"in oil,texas="<<texas<<",&texas="<<&texas<<endl;
-
cout<<"in oil,x="<<x<<",&x="<<&x<<endl;
-
{ //start a block
-
int texas=113;
-
cout<<"in block,texas="<<texas<<",&texas="<<&texas<<endl;
-
cout<<"in block,x="<<x<<",&x="<<&x<<endl;
-
}
-
cout<<"in post-block,texas="<<texas<<",&texas="<<&texas<<endl;
-
}
代码2(auto和register)
运行结果