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

admin2013-02-23  15

问题 下列程序的运行结果是(    )。
   #include<stdio.h>
   voidfun(int*s,int*p)
   {  static int t=3;
   *p=s[t];
   t--;
   }
   void main()
   {  int a[]={2,3,4,5},k;
   int 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://jikaoti.com/ti/XjB0FFFM
0

随机试题
最新回复(0)