设为首页 加入收藏

TOP

C++ Primer Plus复习题及答案(二)
2018-05-21 15:48:12 】 浏览:416
Tags:Primer Plus 习题 答案
;   return 0;

}

void other() {

    int y = 1;

    cout << "Other: " << x << ", " << y << endl;

}

//file2.cpp

#include<iostream>

using namespace std;

extern int x;

namespace {

    int y = -4;

}

void another() {

    cout << "another(): " << x << ", " << y << endl;

}

答: 

10 

Other: 10, 1 

another(): 10, -4

7.下面代码将显示什么内容?

#include<iostream>

using namespace std;

void other();

namespace n1{

    int x = 1;

}

namespace n2 {

    int x = 2;

}

int main() {

    using namespace n1;

    cout << x << endl;

    {

        int x = 4;

        cout << x << ", " << n1::x << "," << n2::x << endl;

    }

    using n2::x;

    cout << x << endl;

    other();

    return 0;

}

void other() {

    using namespace n2;

    cout << x << endl;

    {

        int x = 4;

        cout << x << ", " << n1::x << ", " << n2::x << endl;

    }

    using n2::x;

    cout << x << endl;

}

答: 

4, 1, 2 

4, 1, 2 

2

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇C++11 基于范围的for循环讲解 下一篇关于c++中与的容器(运算符的重载..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目