有以下程序 #include int f(int n) { int t = 0, a=5; if (n/2) {int a=6; t += a++; } else {int a=7; t += a++; } return t + a++; } main

admin2019-05-17  12

问题 有以下程序
#include
int f(int n)
{ int t = 0, a=5;
if (n/2) {int a=6; t += a++; }
else {int a=7; t += a++; }
return t + a++;
}
main()
{ int s=0, i=0;
for (; i<2;i++) s += f(i);
printf("%d\n", s);
}
程序运行后的输出结果是( )。

选项 A、24
B、28
C、32
D、36

答案A

解析 一个源文件中如果外部变量和局部变量同名,则在该局部变量的作用域内,该外部变量会被"屏蔽",main()函数中调用两次f()函数,两次调用均进入else选择支句,t=7,返回7+5=12,所以s=0+f(0)+f(1)=24,答案选A。
转载请注明原文地址:https://jikaoti.com/ti/Qif0FFFM
0

最新回复(0)