首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序 #include <stdio.h> struct pair { int first, second; }; struct pair get_min_max(int* array, int len) { int i; s
有如下程序 #include <stdio.h> struct pair { int first, second; }; struct pair get_min_max(int* array, int len) { int i; s
admin
2021-07-09
22
问题
有如下程序
#include <stdio.h>
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<len; 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=1,max=9
B、min=0,max=9
C、min=1,max=4
D、min=0,max=4
答案
B
解析
在对数组进行初始化时如果在说明数组时给出了长度,但没有给所有的元素赋予初始值,而只依次给前面的几个数组元素赋予初值,那么C语言将自动对余下的元素赋初值0,则array[5] = {9, 1, 3, 4,0}。程序的执行过程为:调用函数get_min_max(array,5),将数组array首地址传入函数,定义结构体变量res,并为其成员赋值。for循环查找数组array数组的最小值0,将其赋值给res的成员first,查找数组最大值9,赋值给res的成员second。最后返回结构体变量res,则min_max=res。输出min_max.first=0,min_max.second=9,B选项正确。
转载请注明原文地址:https://kaotiyun.com/show/oEkp777K
本试题收录于:
二级C语言题库NCRE全国计算机二级分类
0
二级C语言
NCRE全国计算机二级
相关试题推荐
设文件指针fp已定义,执行语句fp=fopen("file","W");后,以下针对文本文件file操作叙述的选项中正确的是
有以下程序#include<stdio.h>intfun(int(*s)[4],intn,intk){intm,i;m=s[0][k];for(i=1;i<n;i++)if(s[i][kl>m)m=s[i][k];returnm:}main
下面属于黑盒测试方法的是
以下叙述中正确的是
设有两行定义语句:intscanf;floatcase;则以下叙述正确的是()。
下列叙述中正确的是( )。
给定程序的功能是:从键盘输入若干行文本(每行不超过80个字符),写到文件myfile4.txt中,用一1作为字符串输入结束的标志。然后将文件的内容读出显示在屏幕上。文件的读写分别由自定义函数ReadText和WriteText实现。请在程序的下划
有以下字符串,说明表达式strlen(s)值的是()。chars[10]={’a’,’\n’,’a’,’b’,’\t’,’c’};
在C语言中,以下说法不正确的是()。
随机试题
BC会计师事务所接受委托,对甲公司2017年财务报表进行审计。注册会计师在工作底稿中记录了所了解的甲公司的情况,部分内容摘录如下。要求:假定各事项均为独立事项,指出所列事项是否可能表明存在重大错报风险。如果认为存在重大错报风险,简要说明理由,并说明该风
甲公司于2014年5月10日申请一项实用新型专利,2017年6月1日获得专利权,2018年5月10日与乙公司签订一份专利独占实施许可合同。对此,下列表述正确的是()。
如题40图所示,8088系统中扩展一片8255A,由8255A的PB口外接8个开关K0~K7作为输入量,由PA口外接8个LED发光二极管L0~L7作为输出量。要求把PB口的输入状态在PA口上输出(即PB口的开关闭合时,其对应PA口的LED亮)。已知:825
我国社会主义的对外贸易全面确立是在()
Hisgoalisnottobecomeasportsman______achampioninacertainfield.
【2013年真题】教育费附加的计税依据是实际缴纳的()税额之和。
某施工单位在基坑作业过程中,降水作业不连续而导致临近2栋民宅基础塌陷,结构出现裂缝;为此居民要求施工单位承担责任,此债务发生的依据是()。
2002年我国的粮食产量约为()。以下说法中,正确的有()。I.2003—2007年我国的粮食产量是逐年增长的Ⅱ.2006年我国的棉花产量不足750万吨Ⅲ.2006年我国的油料产量超过2500万吨Ⅳ.2006年我国的水产品产量不
在下面的函数声明中,存在着语法错误的是
Psychologiststakeopposingviewsofhowexternalrewards,fromwarmpraisetocoldcash,affectmotivationandcreativity.Beha
最新回复
(
0
)