单选题
C语言
题号 #2268712
有以下程序:
#includedstdio.h>
int f(int n);
main( )
{int a=3,s;
s=f(a);s=s+f(a);printf("%dkn",s);
}
int f(int n)
{static int a=1;
n+=a++;
return n;
}
程序运行后的输出结果是( )。
参考答案
C
答案解析
本题考查函数的调用。当执行s=f(a)时,进入fun函数,n=n+(a++),n的值为3,a的值为1,a++的意思是先用a的值,再将a加1为2,所以n的结果为4,也就是主函数中f(a)的结果为4;返回主函数,执行s=s+f(a),s为4,再次调用函数,此时n仍为3,a的值刚才已经自加2,所以计算后n的值为5,a自加l为3。返回主函数,f(a)的结果为5,所以s=4+5=9。
你可能感兴趣的试题
A.10,64
B.10,10
C.64,10
D.64,64
A.struct ord{int x;int Y;int Z;};struet ord a;
B.struct ord{int x;int y;int Z;}struct ord a;
C.struct ord{int X;int Y;int Z;}a;
D.struct{int X;int y;int Z;}a;
A.char str[]="string";c=str;
B.scanf(%s,c):
C.c=getchar( );
D.*c="strin9";