返回列表 回复 发帖

关于 4.5节《赋值》,示例4-6 引发的问题

本人对原来的代码作了一点点增加:


#include "stdafx.h"
#include <iostream.h>

int main(void)
{
        int x=0;
        int y=0;
        cin>>x;
        cin>>y;

        cout<<"x+y="<<(x+=y)<<endl;
        cout<<"x-y="<<(x-=y)<<endl;
        cout<<"x*y="<<(x*=y)<<endl;
        cout<<"x/y="<<(x/=y)<<endl;
        cout<<"x%y="<<(x%=y)<<endl;
        cout<<"x<<y="<<(x<<=y)<<endl;
        cout<<"x>>y="<<(x>>=y)<<endl;
        cout<<"x^y="<<(x^=y)<<endl;
        cout<<"x=y="<<(x=y=100)<<endl;
        return 0;
}


本人输入 8 和 4,得出的结果非常奇怪,为:

8
4
x+y=12
x-y=8
x*y=32
x/y=8
x%y=0
x<<y=0
x>>y=0

x^y=4
x=y=100

请问为什么跟期望值不一样呢?
2# fwbook


谢谢解答!现在明白了!是我自己理解错误。我没留意x会保留前值。
返回列表