下面程序的输出结果是( )。 func(int X) { static int a=2; return (a+=X);} main() { int b=2,c=4,d; d=func(b); d=func(

admin2009-04-15  20

问题 下面程序的输出结果是(  )。    func(int X)    {  static int a=2;    return  (a+=X);}    main()    {  int b=2,c=4,d;    d=func(b);    d=func(c);        printf("%d\n",d);    }

选项 A、4
B、6
C、8
D、12

答案4

解析 func(b)调用函数func并将实参传递给形参x,x的值为2。a+=x=2+2=4,返回值为4。func(c)调用函数func并将实参传递给形参x,x的值为4。因为a被定义为静态的整型变量,当第一次调用函数func返回后a存储单元中的数据仍然保留值为4,所以a+=x=4+4=8。
转载请注明原文地址:https://kaotiyun.com/show/5sWp777K
0

最新回复(0)