以下程序的输出结果是 #include<iostream.h> void main( ) {int x=1,y=3; cout << x++ << ","; {int x

admin2009-02-15  18

问题 以下程序的输出结果是        #include<iostream.h>        void main( )        {int x=1,y=3;          cout  <<  x++  <<  ",";          {int x=0;x+=y*2;            cout  <<X  <<","  <<y  <<  ",";          }        cout << x <<","<< y;        }

选项 A、1,6,3,1,3
B、1,6,3,6,3
C、1,6,3,2,3
D、1,7,3,2,3

答案4

解析 cout<<x++;语句中,程序先输出x的值,然后再加1,所以结果为1,此时x的值为2;在 int x=0;x+=y*2;语句中,将0的值赋给x,然后再运算 x+=y*2的值,结果为x=6(此时x的值为局部变量),y的值不变,在最后在执行了x语句后的值,所以应为2。
转载请注明原文地址:https://kaotiyun.com/show/HKkp777K
0

随机试题
最新回复(0)