首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序 #include struct pair { int first, second; }; struct pair get_min_max(int* array, int len) { int i; struct pair res; res.f
有如下程序 #include struct pair { int first, second; }; struct pair get_min_max(int* array, int len) { int i; struct pair res; res.f
admin
2015-07-28
14
问题
有如下程序
#include
struct pair
{
int first, second;
};
struct pair get_min_max(int* array, int len)
{
int i;
struct pair res;
res.first = array[0];
res.second = array[0];
for (i=1; i
{
if (array
< res.first)
res.first = array
;
if (array
> res.second)
res.second = array
;
}
return res;
}
main()
{
int array[5] = {9, 1, 3, 4};
struct pair min_max = get_min_max(array, 5);
printf("min=%d,max=%d\n", min_max.first, min_max.second);
}
程序运行后的输出结果是( )。
选项
A、min=0,max=9
B、min=1,max=9
C、min=1,max=4
D、min=0,max=4
答案
A
解析
变函数get_min_max()的作用是计算数组array中前n个数据的最大值和最小值,将其记录在结构体变量res中并返回,数组array[5]不完全赋值,没有赋初值的a[4]设为默认值0,所以计算得的最小值和最大值分别为0和9,所以答案选A。
转载请注明原文地址:https://kaotiyun.com/show/9KJp777K
本试题收录于:
二级C语言题库NCRE全国计算机二级分类
0
二级C语言
NCRE全国计算机二级
相关试题推荐
下列程序的输出结果是_______。#defineA100main(){inti=0,sum=0;do{if(i==(i/2)*2)continue;sum+=i;}whil
有以下程序 main() { int i; for(i=0;i<3;i++) switch(i) { case 0: printf("%d",i); case 2: printf("%d",i); default: printf("%d",i); } }
以下程序运行后的输出结果是______。main(){intx=1,y=0,a=0,b=0;switch(x){case1:switch(y){case
设已有定义:char*st="how are you";,下列程序段中正确的是______。
若有定义“int a=10,b=9,c=8;”,顺序执行下列语句后,变量b中的值是______。 c=(a-=(b-5));c=a% 11)+(b=3);
以下对C语言的描述中,正确的是______。
设有定义:structperson{intID;charname[12];}P;请将scanf(“%d”,【】);语句补充完整,使其能够为结构体变量P的成员ID正确读人数据。
设有以下函数:voidfun(intn,char*$s){……}则下面对函数指针的定义和赋值均正确的是
已定义下列函数:intfun(int*p){return*p;)fun函数返回值是()。
随机试题
窗宽窗位均选为100,则CT值的显示范围是
睫状充血的特点不包括()
系统性硬化症患者致残和死亡的主要原因是
医疗保健机构,卫生防疫机构发现传染病时,应当及时采取的控制措施中不包括
中药材入药形式多种多样,其中药材以近成熟果实入药的有
招标人可以向他人透露已获取招标文件的潜在投标人的名称、数量以及可能影响公平竞争的有关招标投标的其他情况。()
We’rehappytoreportthatbusinessisboomingthisyear.
AThebestknownmimosaisthesensitiveplant,BwhoseleavesfoldupandCcollapsesundersuchDstimuliastouch,darkness,ord
A、Toinvitethemantohavedinnerwithher.B、Tosuggestpolitelythatheleave.C、Toaskhimpreparethedinner.D、Toencourag
Twentyyearsagothisweek,theBritishinventorTimBerners-Leecreatedtheworldsfirstwebpage.Itisworth【B1】______theex
最新回复
(
0
)