有以下程序  #include<stdio.h>  main()  {int i,j=0;   char a[]="ab123c4d56ef7gh89";   for(i=0;a[i];i++)   if(a[i]>=’0’&&a[i]<=’9’)  

admin2022-10-24  26

问题 有以下程序
 #include<stdio.h>
 main()
 {int i,j=0;
  char a[]="ab123c4d56ef7gh89";
  for(i=0;a;i++)
   if(a>=’0’&&a<=’9’)
    a[j++]=a
  a[j]=’\0’;
  printf("%s",a);
 }
 程序运行后的输出结果是(          )。

选项 A、123456789abedefgh
B、abcdefgh
C、123456789
D、1234567896ef7gh89

答案C

解析 题干中定义了字符数组a,它包含数字字符和字母字符。通过for循环,将a中所有的数字字符前移,舍去其他字符,并在数字字符后添加字符串结束符“\0”,for循环结束后,字符串a的值为123456789。故本题答案为C选项。
转载请注明原文地址:https://jikaoti.com/ti/xKd0FFFM
0

相关试题推荐
最新回复(0)