首页 > 试题广场 >

#include <stdio.h> main(

[单选题]
#include <stdio.h>
main( )
{
   int i, n=0;
   char c, str[] = "test";
   for(i=0; str[i]; i++)
   {
      c = str[i];
      switch(i)
      {
         case 1:
         case 3:
         case 4:
            putchar(c);
            printf("%d", ++n);
            break;
         default:
            putchar('Q');
      }
   }
}
程序运行结果是:(   )
  • Qe1QQ
  • Qe1Qt2
  • Qe1Qt2Q
  • Qs1QQ
i=0,直接跳到default语句打印Q;i=1,因为switch穿透,直接到case 4打印e和n(n自增后为1),然后break出去;i=2,直接跳到default语句打印Q;i=3,因为switch穿透,直接到case 4打印t和nn自增后为2,然后break出去;i=4循环结束。
编辑于 2021-01-05 10:29:15 回复(0)