Relational and Logical Operators in C language

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

OperatorMeaning
==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

OperatorMeaning
&&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 OperatorsLogical Operators
Values को compare करते हैंConditions को combine करते हैं
Result True/False होता हैResult True/False होता है
Example: a > bExample: (a > b && b > 0)

Exam Points

  • Relational operators comparison करते हैं
  • Logical operators conditions को combine करते हैं
  • Result हमेशा 1 (true) या 0 (false) होता है
  • if और loop statements में इनका उपयोग होता है

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top