C++ Operators
β C++ Operators
Operators wo symbols hote hain jo values aur variables par operations perform karte hain, jaise addition, comparison, logic, etc.
πΉ 1. Arithmetic Operators
| Operator | Meaning | Example |
|---|---|---|
+ |
Addition | a + b |
- |
Subtraction | a - b |
* |
Multiplication | a * b |
/ |
Division | a / b |
% |
Modulus | a % b |
Example:
πΉ 2. Assignment Operators
| Operator | Example | Meaning |
|---|---|---|
= |
a = 5 |
Assign |
+= |
a += 3 |
a = a + 3 |
-= |
a -= 2 |
a = a – 2 |
*= |
a *= 2 |
a = a * 2 |
/= |
a /= 2 |
a = a / 2 |
πΉ 3. Relational (Comparison) Operators
| Operator | Example | Result |
|---|---|---|
== |
a == b |
Equal |
!= |
a != b |
Not equal |
> |
a > b |
Greater |
< |
a < b |
Smaller |
>= |
a >= b |
Greater or equal |
<= |
a <= b |
Smaller or equal |
πΉ 4. Logical Operators
| Operator | Meaning | Example |
|---|---|---|
&& |
AND | a > 5 && b < 10 |
|
||
! |
NOT | !true |
πΉ 5. Increment / Decrement Operators
Pre vs Post
πΉ 6. Bitwise Operators
| Operator | Meaning |
|---|---|
& |
AND |
|
|
^ |
XOR |
~ |
NOT |
<< |
Left shift |
>> |
Right shift |
πΉ 7. Ternary Operator
πΉ 8. sizeof Operator
πΉ 9. Comma Operator
β Common Mistakes
β Correct:
π Summary
-
Operators perform operations
-
Arithmetic, Logical, Relational most common
-
Ternary is shorthand
if-else -
Be careful with
=vs==
