Assignment and Conditional Operators in C language

Introduction

Programming में हमें variables में value store करनी होती है और कई बार उस value को update भी करना पड़ता है।

C language में इस काम के लिए Assignment Operators का उपयोग किया जाता है।

ये operators variable को value assign करने और modify करने के लिए बहुत important होते हैं।

Definition

Assignment Operators वे operators होते हैं जिनका उपयोग variables को value assign करने के लिए किया जाता है।

Types of Assignment Operators

OperatorMeaning
=Assign value
+=Add और assign
-=Subtract और assign
*=Multiply और assign
/=Divide और assign
%=Modulus और assign

Example

int a = 10;
a += 5; // a = a + 5 → 15
a -= 3; // a = a - 3 → 12
a *= 2; // a = a * 2 → 24

Real World Example

मान लो आपके पास एक wallet है:

  • पहले 100 रुपये थे
  • आपने 50 रुपये और डाल दिए → total 150

यह a += 50 जैसा है

Conditional Operator (?:)

Introduction

कभी-कभी हमें program में जल्दी से decision लेना होता है, जैसे दो values में से बड़ी value निकालना।

C language में Conditional Operator (?:) का उपयोग short form में decision लेने के लिए किया जाता है।
यह if-else का छोटा रूप होता है।

Definition

Conditional Operator एक ternary operator है जो condition के आधार पर दो values में से एक को select करता है।

Syntax

condition ? value_if_true : value_if_false;

Example

int a = 10, 
b = 20;
int max = (a > b) ? a : b;

यहाँ:

  • अगर a > b → max = a
  • नहीं तो → max = b

Real World Example

मान लो आपको decide करना है:

  • अगर marks ≥ 40 → Pass
  • नहीं तो → Fail

यह Conditional Operator जैसा है:

Pass/Fail का decision condition पर depend करता है।

Difference Between Assignment and Conditional Operator

Assignment OperatorConditional Operator
Value assign करता हैDecision लेता है
Example: a = 10Example: (a > b) ? a : b
Simple operationCondition based operation

Exam Points

  • = सबसे basic assignment operator है
  • Compound operators (+=, -= आदि) short form होते हैं
  • Conditional operator को ternary operator कहते हैं
  • यह if-else का short form है

Leave a Comment

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

Scroll to Top