有如下程序: #include using namespace std; int fun1(int x) { return ++x; } int fun2(int& x) { re

admin2015-07-22  27

问题 有如下程序:
        #include
        using namespace std;
        int fun1(int x)    { return ++x; }
        int fun2(int& x)   { return ++x; }
        int main() {
        int a=0,b=0,c=0;
            c=fun1(a)+fun2(b);
            cout<            return 0;
        }
运行后的输出结果是

选项 A、002
B、012
C、102
D、112

答案B

解析 程序定义了两个函数,fun1和fun2,功能都是对形参x自增1,然后返回自增后的值,其中fun2的形参x为引用类型,形参x自增1的同时实参的值也自增1;main函数中定义三个整型变量a=0,b=0,c=0,调用fun1(a)返回值为1,调用fun2(b)返回值为1,同时实参b的值被修改为1,所以c的值为1+1=2,程序输出a、b、c为0,1,2;答案为B。
转载请注明原文地址:https://kaotiyun.com/show/MMNp777K
0

随机试题
最新回复(0)