C++ Operators
C++ Operators are symbols that perform operations on variables or other entities that perform mathematical or logical operations for your requirement.
For example, + is an operator used for addition, while - is an operator used for subtraction.
There are basic four types of operators in C++ as shown below:
We can used to C++ arithmetic operators we can perform specific mathematical arithmetic calculation for example:
Operator |
Example |
Operation |
+ |
a + b |
Addition |
- |
a – b |
Subtraction |
* |
a * b |
Multiplication |
/ |
a / b |
Division |
% |
a % b |
Modulo Operation(Remainder after division) |
For Example
Output
Logical operators are used to check either an expression is true or false. If the expression is true, it returns 1 otherwise if the expression is false, it returns 0.
Operator |
Example |
Operation |
|
&& |
expression1 &&expression2 |
Logical AND. True only if all the operands are true. |
|
|| |
expression1 || expression2 |
Logical OR. |
|
! |
expression1! expression2 |
Logical NOT. |
Example
Output
The simple assignment operator is denoted by ‘=’. We are called it that both the left and right sides of the operator must have the same data type. We have different levels of assignment operators as shown below.
Operator |
Example |
Same as |
= |
a = b |
a = b |
+= |
a += b |
a = a+b |
-= |
a -= b |
a = a-b |
*= |
a *= b |
a = a*b |
/= |
a /= b |
a = a/b |
%= |
a %= b |
a = a%b |
For example :
Output :
C++ Comparison Operator can be used to compare two values. When condition value is true return 1 and otherwise false then return 0.
Operator |
Example |
Description |
== |
a == b |
Equal to |
!= |
a != b |
Not equal to |
> |
a > b |
Greater than |
< |
a < b |
Less than |
<= |
a <= b |
Less than equal to |
>= |
a >= b |
Greater than equal to |
For Example
Output