阅读下面的程序: #include<iostream.h> void main() { int x; cin>>x; if(x++>5) cout<<x<<end1; else cout<<x--<<e

admin2012-01-20  15

问题 阅读下面的程序:    #include<iostream.h>    void main()    {    int x;    cin>>x;    if(x++>5)    cout<<x<<end1;    else    cout<<x--<<end1;    }    如果两次执行上述程序,且键盘输入分别为4和6,则输出结果分别是(    )。

选项 A、4,6
B、3,6  
C、4,7
D、5,7

答案D

解析 此题首先读入数值4赋给变量x,因为x++>5不成立,因为“++”后缀,之后x的值变为5,执行语句cout<<x--<<end1;输出:5,之后x的值变为4。当读入的数值是6时,因为x++>5成立,所以执行语句cout<<x<<end1;输出7。
转载请注明原文地址:https://kaotiyun.com/show/0XVp777K
0

最新回复(0)