有以下程序 #include int fun() { static int x=1; x*=2; return x; } main() { int i,s=1; for(i=1;i

admin2016-12-28  24

问题 有以下程序
    #include
    int fun()  {
    static  int x=1;
    x*=2;
    return  x;  }
    main()  {
    int i,s=1;
    for(i=1;i<=3 ; i++)
    s*=fun();
    printf("%d\n",s);}
    程序运行后的输出结果是

选项 A、0
B、10
C、30
D、64

答案D

解析 本题考查了静态局部变量,该局部变量的值在函数调用结束后如果不消失而保留原值。函数fun的功能返回2的乘方,主函数fun函数调用3次,因此第一次s累乘2,第二次累乘4,第三次累乘8,即为2*4*8,值为64。
转载请注明原文地址:https://kaotiyun.com/show/yrDp777K
0

最新回复(0)