首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include<iostream> using namespace std; int main(){ int a[6]={23, 15, 64, 33, 40, 58}; int s1, s2; s
有如下程序: #include<iostream> using namespace std; int main(){ int a[6]={23, 15, 64, 33, 40, 58}; int s1, s2; s
admin
2017-10-17
38
问题
有如下程序:
#include<iostream>
using namespace std;
int main(){
int a[6]={23, 15, 64, 33, 40, 58};
int s1, s2;
s1, s2=a[0];
for(int*p=a+1; p<a+6; p++) {
if(s1>*p)s1=*p;
if(s2<*p)s2=*p;
}
cout<<s1+s2<<end1;
return 0;
}
运行时的输出结果是( )。
A) 23
B) 58
C) 64
D) 79
选项
A、
B、
C、
D、
答案
D
解析
变量s1和s2的初值都等于23,那么在执行第一次for循环时,*p的值等于15,它小于23,所以把15赋给变量s1;执行第二次for循环时,*p的值等于64,它大于23,所以把64赋给变量s2;而数组a中a[2]后面的元素的值都大于15,小于64,因而变量s1,s2的值不会再发生变化,最终值为15+6=79,所以程序输出79。
转载请注明原文地址:https://kaotiyun.com/show/FJAp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
已知doublevar;是文件F1.CPP中的一个全局变量定义,若文件F2.CPP中的某个函数也需要访问,则在文件F2.CPP中var应说明为______。
一个类中有【 】个构造函数。
以下关于静态成员变量的叙述不正确的是
下列关于关系运算的叙述中正确的是
程序设计方法要求在程序设计过程中
有如下类定义:classTest{public:Test(){a=0;c=0}//①intf(inta)const{this->a=a;}//②
如果一个工人可管理多个设备,而一个设备只被一个工人管理,则实体“工人”与实体“设备”之间存在______关系。
有关析构函数的说法中错误的是
在双目运算符中需要声明其右操作数时,完成的是【 】重载,而需要声明全部操作数时,完成的是【 】重载。
在长度为n的有序线性表中进行二分查找,需要的比较次数为
随机试题
Thenwhereareourrelatives?myfather?ourfamilyfriends?Youclaimtherightsofamother;therighttocallmefoolandchi
Manypeoplewronglybelievethatwhenpeoplereacholdage,theirfamiliesplacetheminnursinghomes.Theyareleftinthe【C1】
为了计数寄生虫虫卵,应采集多少时间内的全部粪便
某一弱酸的标准解离常数为1.0×10-5则相应强碱弱酸盐MA的标准水解常数为()。
矿井的物理定向方法有()。
关于原癌基因特点的叙述,下列哪项是错误的
对比目鱼捕捞量做进一步的限制会影响到消费者。由于供求关系,这种捕捞量的限制可能会导致比目鱼价格的上涨。以下哪项假设最能支持比目鱼的价格会上升这一结论?
新奥尔良方法将数据库设计分为4个阶段,它们是()。
Inrecentyears,moreandmoreforeignersareinvolvedintheteachingprogramsoftheUnitedStates.Bothoftheadvantagesand
Oneday,drought(干旱)maybeathingofthepastatleastincoastalcities.Vastareasofdesertthroughouttheworldmayforthe
最新回复
(
0
)