有以下程序 #include<stdio.h> int fun(char s[]) main() {int n==0; {char s[10]={’6’

admin2020-05-19  17

问题 有以下程序
    #include<stdio.h>
    int fun(char s[])                  main()
    {int n==0;                        {char s[10]={’6’,’1’,’*’,’4’,’*’,’9’,’*’,’0’,’*’};      while(*s<=’9’&&*s>=’0’)                 printf("%d\n",fun(s));
      {n=10*n+*s-’0’;s++;}          }
    return(n);}
程序的运行结果是

选项 A、61490
B、61
C、9
D、5

答案B

解析 在fun函数中,while循环的功能是逐个取字符数组s的字符判断其是否是数字。若是则将这些数字组成一个数保存到变量n中,并返回变量n的值。所以在主函数中调用fun(s)时,将把字符数组s中的数字组成一个数输出。因为当指针s指向数组的第3位时,即字符’*’,循环条件不成立,循环结束,返回n的值。所以输出n的值为61。
转载请注明原文地址:https://kaotiyun.com/show/QgCp777K
0

最新回复(0)