有如下程序 #include <stdio.h> struct pair { int first, second; }; struct pair get_min_max(int* array, int len) { int i;

admin2019-07-25  27

问题 有如下程序
#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[6] = {19, 21, 3, 4};
    struct pair  min_max = get_min_max(array, 6);
    printf("min=%d,max=%d\n", min_max.first, min_max.second);
}
程序运行后的输出结果是

选项 A、min=0,max=6
B、min=1,max=20
C、min=1,max=19
D、min=0,max=21

答案D

解析 本题首先在main函数定义一个数组array,然后定义了一个结构变量min_max,min_max使用函数get_min_max的返回值初始化,函数get_min_max的功能就是将数组中的最小值和最大值取出来后分别赋值给结构变量min_max中的first,second两个整形变量,数组长度为6个单位,初始化4个数据,剩下2个默认为0,因此答案为D选项。
转载请注明原文地址:https://kaotiyun.com/show/VpID777K
0

最新回复(0)