运算符(个人学习笔记黑马学习)

算数运算符

 加减乘除

#include 
using namespace std;

int main() {

	int a1 = 10;
	int a2 = 20;

	cout << a1 + a2 << endl;
	cout << a1 - a2 << endl;
	cout << a1 * a2 << endl;
	cout << a1 / a2 << endl;


	/*double a3 = 0.5;
	double a4 = 0.25;
	cout << a3 / a4 << endl;*/
	double a3 = 0.5;
	double a4 = 0.22;
	cout << a3 / a4 << endl;//运算结果也可以是小数

	system("pause");
	return 0;
}

运算符(个人学习笔记黑马学习)_第1张图片


取模  

#include 
using namespace std;

int main() {

	int a1 = 10;
	int b1 = 3;
	cout << a1 % b1 << endl;

	/*两个小数之间不可以做取余运算
	double d1 = 0.2;
	double d2 = 0.55;
	count << d1 % d2 << endl;
	*/
	

	system("pause");
	return 0;
}


自增自减 

#include 
using namespace std;

int main() {

	//前置
	int a2 = 10;
	int b2 = ++a2 * 10;
	cout << "a2 = " << a2 << endl;
	cout << "b2 = " << b2 << endl;


	//后置
	int a3 = 10;
	int b3 = a3++ * 10;
	cout << "a3 =" << a3 << endl;
	cout << "b3 =" << b3 << endl;
	system("pause");
	return 0;
}

运算符(个人学习笔记黑马学习)_第2张图片

  


赋值运算符

#include 
using namespace std;

int main() {

	// =
	int a = 10;
	a = 100;
	cout << "a=" << a << endl;

	// +=
	a = 10;
	a += 2;
	cout << "a=" << a << endl;

	// -=
	a = 10;
	a -= 2;
	cout << "a=" << a << endl;

	// *=
	a = 10;
	a *= 2;
	cout << "a=" << a << endl;


	// /=         
	a = 10;
	a /= 2;
	cout << "a=" << a << endl;

	// %=
	a = 10;
	a %= 2;
	cout << "a=" << a << endl;


	system("pause");
	return 0;
}

运算符(个人学习笔记黑马学习)_第3张图片


比较运算符 

#include 
using namespace std;

int main() {

	//==
	int a = 10;
	int b = 20;
	cout << (a == b) << endl;

	//!=
	cout << (a != b) << endl;

	//>
	cout << (a > b) << endl;

	//<
	cout << (a < b) << endl;

	//>=
	cout << (a >= b) << endl;

	//<=
	cout << (a <= b) << endl;


	system("pause");
	return 0;
}

运算符(个人学习笔记黑马学习)_第4张图片


逻辑运算符 

逻辑非!

#include 
using namespace std;

int main() {

	int a = 10;
	cout << !a << endl;
	cout << !!a << endl;

	system("pause");
	return 0;
}


逻辑与&& 

#include 
using namespace std;

int main() {

	int a = 10;
	int b = 10;
	cout << (a && b) << endl;

	a = 0;
	b = 10;
	cout << (a && b) << endl;

	a = 0;
	b = 0;
	cout << (a && b) << endl;

	system("pause");
	return 0;
}

运算符(个人学习笔记黑马学习)_第5张图片


逻辑或|| 

#include 
using namespace std;

int main() {

	int a = 10;
	int b = 10;
	cout << (a || b) << endl;

	a = 0;
	b = 10;
	cout << (a || b) << endl;

	a = 0;
	b = 0;
	cout << (a || b) << endl;

	system("pause");
	return 0;
}

运算符(个人学习笔记黑马学习)_第6张图片

你可能感兴趣的:(c++学习笔记,学习,笔记,c++)