为了账号安全,请及时绑定邮箱和手机立即绑定

关于未命名名称空间

关于未命名名称空间

C C++
xungeer29 2017-10-28 18:28:55
// file1.cpp #include <iostream> using namespace std; void other(); void another(); int x = 10; int y; int main() {  cout << x << endl;  {   int x = 4;   cout << x << endl;   cout << y << endl;        //这里y为什么输出0?  }  other();  another();  return 0; } void other() {  int y = 1;  cout << "Other: " << x << ", " << y << endl; } // file 2.cpp #include <iostream> using namespace std; extern int x; namespace { int y = -4; } void another() { cout << "another(): " << x << ", " << y << endl; }
查看完整描述

1 回答

已采纳
?
慕移动6052691

TA贡献22条经验 获得超7个赞

y为全局变量,默认初始值为0

查看完整回答
反对 回复 2017-10-28
  • 1 回答
  • 0 关注
  • 1118 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信