问题
单项选择题
有如下程序:
#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
答案
参考答案: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。