♦ C++ Operators
♣ About C++ Operators
Operators in C++ are fundamentally used to perform operations on Variables and Values.Various types of Operators exist in C++.
- Comparison Operators
- Arithmetic Operators
- Assignment Operators
- Logical Operators
- Identity Operators
- Membership Operators
- Bitwise Operators
♣ Example1: Comparison Operators in C++
Comparison operator perform comparison between two variable at base level and output a boolean(true/false) value.Below is the list of comparison operators.
- Greater Than: a > b
- Greater Than or Equal to: a >= b
- Less Than: a < b
- Less Than or Equal to: a <= b
- Equal to: a == b
- Not Equal to: a != b
Example
Input:
Output:
♣ Example2: Arithematic Operators in C++
Arithmetic Operations in Python are used to perform Mathematical Operations.Operator | Working |
---|---|
+ | Addition |
- | Subtraction |
* | Multiplication |
/ | Division |
% | Modulo |
++ | Increment |
-- | Decrement |
Example
Input:
Output:
♣ Example3: Assignment Operators in C++
Assignment Operations in Python are used for assignment of (values)/(variable values) to variables.Operator | Working |
---|---|
= | Data Assignment |
+= | Addition Increment |
-= | Subtraction Decrement |
*= | Multiplication Increment |
/= | Division Decrement |
%= | Modulo Assignment |
Example
Input:
Output:
♣ Example4: Logical Operators in C++
Logical Operators in C++ are used to evaluate conditional statements and produce Boolean output.Operator | Working |
---|---|
&& | returns True if all variables/statements are True |
|| | returns True if atleast one variables/statements are True |
~ | returns the reverse of Boolean value |
Example
Input:
Output: