给定程序中,函数fun()的功能是:使数组中的元素的值增加10倍。 改正其中的错误,使它能得出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构. 试题程序: #include<stdio.h>

admin2010-09-14  24

问题 给定程序中,函数fun()的功能是:使数组中的元素的值增加10倍。
   改正其中的错误,使它能得出正确的结果。
   注意:不要改动main函数,不得增行或删行,也不得更改程序的结构.
   试题程序:
    #include<stdio.h>
   #include<conio.h>
   iht m[10];
   void fun(void)
   {
    int j;
   printf("In subfunc after calling\n");
   for(j=0;j<l0;j++)
      {
   /************found**********************/
    printf("%3d",m[j]*l0);
    }
    }
   main()
   { int i;
    printf("In main before calling\n");
    for (i=0; i<10; i++)
       {
       m=i;
       printf ("%3d",m);
      }
    fun ();
    printf("\nIn main after calling\n");
    for (i=0; i<10; i++)
         printf ("%3d",m);
    getch ();
   }

选项

答案错误:printf("%3d" m[j]*10); 正确:printf("%3d" m[j]=m[j]*10

解析 本题考查全局变量相关知识。该题程序中的fun()没有参数输入,但数组m[10]为全局变量,故可在fun()函数中使用,fun()函数对数组m的操作可以反映到主函数的输出结果中。
转载请注明原文地址:https://kaotiyun.com/show/aWID777K
0

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