【小练习】程序设计基本概念:赋值语句_常用运算符1
1.练习源码
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int x=2, y, z;
x *= (y=z=5); cout << x << endl;
z = 3;
x == (y=z); cout << x << endl;
x = (y==z); cout << x << endl;
x = (y&z); cout << x << endl;
x = (y&&z); cout << x << endl;
y = 4;
x = (y|z); cout << x << endl;
x = (y||z); cout << x << endl;
return 0;
}
2.关键点分析
2.1 运算符作用
符号 |
作用 |
x*=y |
x = x*y |
x==y |
x等于y,返回1;x不等于y,返回0 |
x&y |
x和y按位与 |
x&&y |
x和y都为真,返回1;否则返回0 |
x|y |
x和y按位或 |
x||y |
x和y都为假,返回0;否则返回1 |
2.2 计算过程及答案
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int x=2, y, z;
x *= (y=z=5); cout << x << endl;
z = 3;
x == (y=z); cout << x << endl;
x = (y==z); cout << x << endl;
x = (y&z); cout << x << endl;
x = (y&&z); cout << x << endl;
y = 4;
x = (y|z); cout << x << endl;
x = (y||z); cout << x << endl;
return 0;
}
