Chapter 3 - Operators in C++
Chapter 3 - Operators in C++
Chapter 3 - Operators in C++
2
Operators in C++ can be classified into 6 types:
1. Arithmetic Operators
2. Assignment Operators
3. Relational Operators
4. Logical Operators
5. Bitwise Operators
6. Other Operators
3
1. C++ Arithmetic Operators
Arithmetic operators are used to perform arithmetic operations on variables and data. For
example,
Here, the + operator is used to add two variables a and b. Similarly there are various other
arithmetic operators in C++.
4
Output:
a+b=9
a–b=5
a + b =14
Here, the operators
+, - and * compute
a/b=3
addition,subtraction, a%b=1
and multiplication
respectively as we
might have
expected.
5
/ Division Operator
Note the operation (a / b) in our program. The / operator is the division operator.
% Modulo Operator
6
Increment and Decrement Operators
C++ also provides increment and decrement operators: ++ and -- respectively.
For example,
7
Example 2: Increment and Decrement Operators
Output
8
2. C++ Assignment Operators
In C++, assignment operators are used to assign values to variables. For example,
9
Example 3: Assignment Operators
Output:
10
3. C++ Relational Operators
A relational operator is used to check the relationship between two operands. For example,
11
Example 4: Relational Operators
Output
12
4. C++ Logical Operators
Logical operators are used to check whether an expression is true or false. If the expression
is true, it returns 1 whereas if the expression is false, it returns 0.
13
14
Example 5: Logical Operators
Output
15
Explanation of logical operator program
17
6. Other C++ Operators
Here's a list of some other common operators available in C++.
18
Source:
https://www.programiz.com/cpp-programming/operators
19
20