下列程序的运行结果是( )。 #include<stdio.h> void fun(int*s,int*p) {static int t=3; *p=s[t]; t--; } void main() {

admin2011-06-10  18

问题 下列程序的运行结果是(    )。    #include<stdio.h>    void fun(int*s,int*p)    {static int t=3;    *p=s[t];    t--;    }    void main()    {int a[]={2,3,4,5},k,x;    for(k=0;k<4;k++)    {fun(a,&x);    printf("%d,",x);    }    }

选项 A、5,4,3,2,
B、2,3,4,5,
C、2,2,2,2,
D、5,5,5,5,

答案A

解析 分析fun函数程序段,可知fun函数要实现的功能是将s中第(t+1)个元素以前的元素逆置赋给数组p。由于fun函数定义了静态变量t=3,因此,在主函数中调用函数fun(a,&x)时,就是要将数组a中前4个元素逆置赋给数组x,最后输出x数组。
转载请注明原文地址:https://kaotiyun.com/show/HRPp777K
0

最新回复(0)