Introduction
Programming में हमें कई बार conditions check करनी होती हैं, जैसे:
- क्या एक value दूसरी से बड़ी है?
- क्या दोनों conditions true हैं?
इन सभी comparisons और conditions को check करने के लिए C language में Relational और Logical Operators का उपयोग किया जाता है।
ये operators decision making (if, while आदि) में बहुत महत्वपूर्ण भूमिका निभाते हैं।
Relational Operators
Definition
Relational Operators वे operators होते हैं जो दो values के बीच comparison करते हैं और result True (1) या False (0) में देते हैं।
Types of Relational Operators
| Operator | Meaning |
|---|---|
| == | Equal to |
| != | Not equal to |
| > | Greater than |
| < | Less than |
| >= | Greater than or equal to |
| <= | Less than or equal to |
Example
int a = 10, b = 5;
printf("%d\n", a > b); // 1 (true)
printf("%d\n", a == b); // 0 (false)
Real World Example
मान लो आप दो लोगों की height compare कर रहे हैं:
- Rahul > Mohan → Rahul लंबा है
यह comparison Relational Operator जैसा है।
Logical Operators
Definition
Logical Operators वे operators होते हैं जो दो या अधिक conditions को combine करके final result (True या False) देते हैं।
Types of Logical Operators
| Operator | Meaning |
|---|---|
| && | AND |
| || | OR |
| ! | NOT |
Example
int a = 10, b = 5;
if (a > 5 && b > 2)
{
printf("Both conditions are true");
}
Real World Example
मान लो आपको movie देखने जाना है, लेकिन condition है:
- पैसे भी होने चाहिए AND time भी होना चाहिए
अगर दोनों condition true हैं, तभी आप जा सकते हैं।
यह Logical AND (&&) जैसा है।
Difference Between Relational and Logical Operators
| Relational Operators | Logical Operators |
|---|---|
| Values को compare करते हैं | Conditions को combine करते हैं |
| Result True/False होता है | Result True/False होता है |
| Example: a > b | Example: (a > b && b > 0) |
Exam Points
- Relational operators comparison करते हैं
- Logical operators conditions को combine करते हैं
- Result हमेशा 1 (true) या 0 (false) होता है
- if और loop statements में इनका उपयोग होता है