5章5节局部参数的作用域

来源:互联网 发布:绝牛网身份证查询软件 编辑:程序博客网 时间:2024/06/02 06:54

#include <iostream>

void myfunc();
int main()
{
 using namespace std;

 int x=5; // 在main函数里 X=5
 cout << " in main x is " << x << endl;

 myfunc(); //开始调用函数 myfunc()
  cout << " back in main x is " << x << endl;

 return 0;
}
void myfunc()
{
 using namespace std;
 
 int x=10;//赋值=10
 cout << " in myfunc x is " << x << endl;
{
 int x =9;//在myfunc()内部的一个{}内赋值X=9
 cout << " now ,in myfunc x is " << x << endl;
 
}
     cout << "out of myfunc in myfunc x is " << x << endl;
  // 跳出{}X返回10
} // myfunc() 函数结束 返回执行 main函数的最后一行

原创粉丝点击