03 Operators & Expressions
Operators wo symbols hain jo variables par kuch kaam (operation) karte hain.
1. Arithmetic Operators (Maths) ➕
| Operator | Name | Example |
|---|---|---|
+ | Addition | a + b |
- | Subtraction | a - b |
* | Multiplication | a * b |
/ | Division | a / b (Integer division gives integer!) |
% | Modulus (Remainder) | a % b (10 % 3 = 1) |
int a = 10, b = 3;printf("%d", a / b); // Output: 3 (3.33 nahi aayega kyunki int hai)printf("%d", a % b); // Output: 1 (Remainder)2. Relational Operators (Tulna) ⚖️
Ye check karte hain ki do values barabar hain ya nahi. Result 1 (True) ya 0 (False) hota hai.
==: Kya barabar hai?!=: Kya barabar NAHI hai?>/<: Bada / Chhota>=/<=: Bada ya barabar / Chhota ya barabar
int x = 5, y = 10;printf("%d", x > y); // Output: 0 (False)3. Logical Operators (Dimag) 🧠
Multiple conditions check karne ke liye.
&&(AND): Dono sahi hone chahiye.||(OR): Koi ek bhi sahi ho to chalega.!(NOT): Sach ko jhooth, jhooth ko sach kar deta hai.
int age = 20, money = 500;if (age > 18 && money > 100) { printf("Party time! 🥳");}4. Increment/Decrement (++ / --) ⬆️
a++(Post-increment): Pehle use karo, fir badhao.++a(Pre-increment): Pehle badhao, fir use karo.
int x = 5;printf("%d", x++); // Prints 5, then x becomes 6printf("%d", x); // Prints 65. Ternary Operator (Shortcut If-Else) ⚡
Condition ? True : False
int age = 20;(age >= 18) ? printf("Adult") : printf("Minor");