首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include<iostream> using namespace std; int fun(char x,char y) { if(x>y) return x: return y; } int main() { int a(9),b(8)
有如下程序: #include<iostream> using namespace std; int fun(char x,char y) { if(x>y) return x: return y; } int main() { int a(9),b(8)
admin
2021-05-06
21
问题
有如下程序:
#include<iostream>
using namespace std;
int fun(char x,char y)
{
if(x>y)
return x:
return y;
}
int main()
{
int a(9),b(8),c(7);
cout<<fun(fun(a,b),fun(b,c));
return0;
}
运行后的输出结果是( )。
选项
A、8
B、9
C、7
D、函数调用出错
答案
B
解析
程序中,fun()函数的作用是将形参x、y中的较大值作为函数值返回;main()函数首先使用直接初始化方式,初始化a的值为9,b的值为8,c的值为7,然后调用函数:fun(fun(a,b),fun(b,c));并将返回值输出,由于a>b,b>c,所以fun(fun(a,b),fun(b,c))等价于:fun(a,b),也就等价于a。本题答案为B选项。
转载请注明原文地址:https://kaotiyun.com/show/NHfp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下列情况中,不会调用拷贝构造函数的是()。
下列有关类继承的叙述中,错误的是()。
下面对软件测试描述错误的是
在对函数进行原型声明时,下列语法成分中不需要的是
静态数据成员在()进行初始化。
下列关于类模板的叙述中,正确的是()。
有如下类和对象的定义:classConstants{public;staticdoublegetPl0{retum3.1416;});Constantsconstants;下列各组语句中
下列选项中,正确的C++标识符是
T列数据结构中,能用二分法进行查找的是
下面不属于软件设计阶段任务的是
随机试题
下列选项属于全球化管理文化环境的有()
以下哪一方剂,不宜用治妇人崩漏
以下预算中,不以销售预算为基础的是()。
2008年1月1日甲公司向张某借款100000元,借款期限1年,年利率8%。张某当年取得某境外上市分红2000元。张某2008年利息、分红收入应缴纳个人所得税()元。
某资本家投资100万元创办企业从事生产,60万元用于固定资本、以购买机器设备等,40万元用于流动资本、以购买原材料和劳动力等(其中购买劳动力支付了10万元)。一轮生产结束后,该企业的总资本达到了120万元。那么,该企业的剩余价值率为()
设有关系R,S和T如下。关系T是由关系R和S经过哪种操作得到的?
一个工作人员可以使用多台计算机,而一台计算机可被多个人使用,则实体工作人员与实体计算机之间的联系是()。
Itisnoteasytopin-pointthe【C1】______oftheChristmasfeast,todaythemostimportantfeastoftheChristmasseasoninmos
______dependsonwhereyoulive.
Whatdoesthemanmean?
最新回复
(
0
)