//5-3 compare symbol
#include <iostream>
using namespace std;
//== equal
//!= unequal
//> bigger than
//< smaller than
//>= bigger than or equal to
//<= smaller than or equal to
int main() {
int a = 6;
int b = 9;
cout << (a == b) << endl; //because << ‘s level is much higher than ==, so we must add () to solve the problem
cout << (a != b) << endl;
cout << (a > b) << endl;
cout << (a < b) << endl;
cout << (a >= b) << endl;
cout << (a <= b) << endl;
return 0;
}
//5 – 4 logic symbol
#include <iostream>
using namespace std;
//&& and
//|| or
//! not
//the priority : ||<&&<!
// one number symbol’s class is the highest
//if you don’t know the class, you can add some () into it
int main() {
//two values has 2^2 kinds of outcomes
//1. && and calculate: if have false, there must false
cout << (0 && 0) << endl;
cout << (0 && 1) << endl;
cout << (1 && 0) << endl;
cout << (1 && 1) << endl; //when all the maniplate numbers are true, the outcome must true, otherwise the outcome is false
cout << (0 && 0) << endl;
cout << (0 && 2) << endl;
cout << (2 && 0) << endl;
cout << (2 && 2) << endl;//when all the maniplate numbers are true, the outcome must true, otherwise the outcome is false
// 2 or more the same as 1, because of the algorithm only care about the number is 1 or not 1
cout << “———” << endl;
//2.|| or calculate:where there have one true, there must true
cout << (0 || 0) << endl;
cout << (0 || 2) << endl;
cout << (2 || 0) << endl;
cout << (2 || 2) << endl;// this wave line inform me there is only need one true before the ||
cout << “———” << endl;
//3. ! not calculate:not true is false, not false is true
cout << !0 << endl;
cout << !2 << endl;
cout << “———” << endl;
int a = !((5 > 4) && (7 – 8) && (0 – 1));
cout << a << endl;
int b = !(1 || 1 && 0); // the && and symbol’s class is higher than the || or maniplate symbol
cout << b << endl;
return 0;
}
//5 – 5, comma symbol
#include <iostream>
using namespace std;
int main() {
int a = 1;//must has an origin value
//a = 5 – 6, 8 + 9, 100 / 7;//the , comma ‘s priority is really low, lower than the = ,so we must add () into it
a = (5 – 6, 8 + 9, 100 / 7);//the , comma ‘s priority is really low, lower than the = ,so we must add () into it
//-1 ,17 ,14
//the comma symbol will output the last value
cout << a << endl;
//example 1:
int x = 4;
int y = 5;
cout << x << ” ” << y << endl;
int temp = x;
x = y;
y = temp;
cout << x << ” ” << y << endl;
//we can use it in a loop,which can easily change the value
temp = x, x = y, y = temp;
cout << x << ” ” << y << endl;
return 0;
}