Operators in C++
📘 C++
👁 30 views
📅 Dec 22, 2025
⏱ Estimated reading time: 2 min
An operator is a symbol used to perform operations on variables and values.
1. Arithmetic Operators
Used for mathematical calculations.
| Operator | Description | Example |
|---|---|---|
+ | Addition | a + b |
- | Subtraction | a - b |
* | Multiplication | a * b |
/ | Division | a / b |
% | Modulus (remainder) | a % b |
2. Relational (Comparison) Operators
Used to compare values.
| Operator | Description | Example |
|---|---|---|
== | Equal to | a == b |
!= | Not equal to | a != b |
> | Greater than | a > b |
< | Less than | a < b> |
>= | Greater than or equal to | a >= b |
<= | Less than or equal to | a <= b |
3. Logical Operators
Used to combine conditions.
| Operator | Description | Example |
|---|---|---|
&& | Logical AND | a > 0 && b > 0 |
| ` | ` | |
! | Logical NOT | !a |
4. Assignment Operators
Used to assign values.
| Operator | Description | Example |
|---|---|---|
= | Assign | a = 5 |
+= | Add and assign | a += 2 |
-= | Subtract and assign | a -= 2 |
*= | Multiply and assign | a *= 2 |
/= | Divide and assign | a /= 2 |
5. Increment and Decrement Operators
Used to increase or decrease a value by 1.
| Operator | Description | Example |
|---|---|---|
++ | Increment | a++ |
-- | Decrement | a-- |
6. Bitwise Operators
Used for bit-level operations.
| Operator | Description | Example |
|---|---|---|
& | AND | a & b |
| ` | ` | OR |
^ | XOR | a ^ b |
~ | NOT | ~a |
<< | Left shift | a << 1> |
>> | Right shift | a >> 1 |
7. Conditional (Ternary) Operator
Used as a short form of if-else.
8. Special Operators
-
sizeof– returns size of a data type -
,(comma) – evaluates multiple expressions -
.– accesses class members -
->– accesses members using pointers
Key Points
-
Operators perform operations on data
-
Different operators serve different purposes
-
Correct operator usage is essential for logic building
Conclusion
Operators are fundamental building blocks in C++ programs that allow computation, comparison, and decision-making.
🔒 Some advanced sections are available for Registered Members
Register Now
Register Now
Share this Post
← Back to Tutorials