下列程序的输出结果是______. #include <stdio.h> fun () { static int a=O; a+=3; printf("%d",a); } main () { int

admin2010-05-22  19

问题 下列程序的输出结果是______.
   #include <stdio.h>
   fun ()
   {   static int a=O;
       a+=3; printf("%d",a);
   }
   main ()
   {   int cc;
       for (cc=1;cc<5;cc++) fun();
       printf ("\n");
   }

选项

答案3 6 9 12

解析 本题考查最基本的for循环:for(cc=1;cc<5;cc++)规定循环次数为4次,每次a+=3即每次a的值增3,但因为fun函数中变量 a为static类型,所以每次调用完子函数之后,变量a所做的改变都要保存。
转载请注明原文地址:https://kaotiyun.com/show/TAWp777K
0

最新回复(0)