C++ introductory tutorial -4 operators

Arithmetic operator



+ – * / don’t say,

% is the remainder of 3%. 2 is 1

++ is the value itself +1 a=1; a++; So a becomes 2

I could write this as a++ or plus +a, but it makes a difference, whether it comes first or after

Example:

a=1;

cout<<a++;

Example 1, print first, then +, print 1

a=1;

cout<<++a;

Example 2, it’s +, then it prints, then it prints 2

Relational operator

This is usually used in conjunction with the if condition statement to check whether it is true or false:

a=1;
b=2;
if(a! =b)// Check whether a! =b{cout<< "A does not equal b"; }Copy the code

Logical operator

If (a & b) / / here use && as examples is a true, b is true, a && b result is true The meaning of this is and {} the if (a | | b) / / used here | | as an example of a and b is only one true, a && b result is true This means or {}

Example:

a=1;
b=2;
if(a==1 && b==1) // if a==1, b==1, b==1, b==1, a==1, b==1, b==1, b==1
Copy the code