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

admin2019-06-12  56

问题 阅读下面的程序:
    #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://jikaoti.com/ti/qJA0FFFM
0

最新回复(0)