आज आप सीखने वाले हैं, Operator in C in Hindi में। Operator in C सीखना हर उस व्यक्ति के लिए बहुत जरूरी है जो C programming की शुरुआत कर रहें है। जब हम कोई program लिखते हैं, तो हमें numbers जोड़ने, घटाने, compare करने या logic लगाने की जरूरत होती है — और यह सब काम operators के द्वारा किये जाते हैं।
इस blog post में हम बिल्कुल आसान भाषा में समझेंगे कि operator क्या होते हैं, यह कितने प्रकार के होते हैं, और हर प्रकार के operator का उपयोग कहाँ और कैसे किया जाता है। हर topic के साथ हम एक real code example भी देखेंगे, ताकि आपको समझने में कोई दिक्कत न हो।
अगर आप C programming सीखने की शुरुआत कर रहे हैं, तो यह post आपके लिए एकदम सही जगह है। यहाँ आप Arithmetic, Relational, Logical, Bitwise, Assignment और कई अन्य operators के बारे में step-by-step सीखेंगे। तो चलिए शुरू करते हैं!
Table of Contents
Operator क्या होता है? (What is an Operator in C?)
Operator एक ऐसा symbol होता है जो compiler को बताता है कि किस तरह का mathematical या logical काम करना है। जैसे कि + जोड़ने का काम करता है, – घटाने का काम करता है, और > compare करने का काम करता है।
उदाहरण के लिए:
int a = 10 + 5;
यहाँ + एक operator है, और 10 और 5 उसके operands हैं।
C language में operators को उनके काम के हिसाब से कई भागों में बाँटा गया है। आइए एक-एक करके सभी को समझते हैं।

1. Arithmetic Operators (गणितीय Operators)
Arithmetic operators वे operators हैं जो basic mathematical काम करते हैं जैसे जोड़, घटाव, गुणा, भाग आदि।
| Operator | काम | उदाहरण |
|---|---|---|
| + | जोड़ (Addition) | a + b |
| – | घटाव (Subtraction) | a – b |
| * | गुणा (Multiplication) | a * b |
| / | भाग (Division) | a / b |
| % | शेषफल (Modulus) | a % b |
Arithmetic Operator Example Code:
#include <stdio.h>
int main() {
int a = 20, b = 6;
// Performing arithmetic operations
printf("Addition : %d\n", a + b);
printf("Subtraction : %d\n", a - b);
printf("Multiplication: %d\n", a * b);
printf("Division : %d\n", a / b);
printf("Remainder : %d\n", a % b);
return 0;
}
ध्यान दें: % Modulus operator सिर्फ integers के साथ काम करता है, floating point numbers के साथ नहीं।
2. Relational Operators (तुलना करने वाले Operators)
जब हमें दो values की आपस में तुलना करनी होती है, तब Relational operators का उपयोग करते हैं। ये operators हमेशा 1 (true) या 0 (false) return करते हैं।Operator in C in Hindi के इस भाग को ध्यान से समझें क्योंकि यह conditions और loops में बहुत काम आता है।
| Operator | मतलब | उदाहरण |
|---|---|---|
| == | बराबर है | a == b |
| != | बराबर नहीं है | a != b |
| > | बड़ा है | a > b |
| < | छोटा है | a < b |
| >= | बड़ा या बराबर | a >= b |
| <= | छोटा या बराबर | a <= b |
Relational Operator Example Code:
#include <stdio.h>
int main() {
int a = 10, b = 20;
// Comparing two numbers
printf("a == b : %d\n", a == b); // Equal to
printf("a != b : %d\n", a != b); // Not equal to
printf("a < b : %d\n", a < b); // Less than
printf("a > b : %d\n", a > b); // Greater than
return 0;
}
3. Logical Operators (तार्किक Operators)
Logical operators का उपयोग तब होता है जब हमें एक से ज्यादा conditions को एक साथ check करना हो। ये भी 1 या 0 return करते हैं।
| Operator | मतलब | उदाहरण |
|---|---|---|
| && | AND – दोनों सच हों | a > 5 && b < 20 |
| || | OR – कोई एक सच हो | a > 5 || b < 5 |
| ! | NOT – उलटा | !(a > 5) |
Logical Operator Example Code:
#include <stdio.h>
int main() {
int a = 10, b = 15;
// Using logical operators
printf("a > 5 && b > 10 : %d\n", a > 5 && b > 10);
printf("a > 15 || b > 10: %d\n", a > 15 || b > 10);
printf("!(a > 5) : %d\n", !(a > 5));
return 0;
}
AND (&&) तभी true होगा जब दोनों conditions true हों। OR (||) तब true होगा जब कोई एक condition true हो।
4. Assignment Operators (मान देने वाले Operators)
Assignment operators का काम variable में कोई value रखना होता है। = सबसे basic assignment operator है।
| Operator | मतलब | उदाहरण |
|---|---|---|
| = | मान देना | a = 10 |
| += | जोड़कर रखना | a += 5 (यानी a = a + 5) |
| -= | घटाकर रखना | a -= 5 |
| *= | गुणा करके रखना | a *= 2 |
| /= | भाग करके रखना | a /= 2 |
| %= | शेषफल रखना | a %= 3 |
Assignment Operator Example Code:
#include <stdio.h>
int main() {
int a = 10;
// Using addition assignment operator
a += 5;
printf("After a += 5 : %d\n", a);
// Using subtraction assignment operator
a -= 3;
printf("After a -= 3 : %d\n", a);
// Using multiplication assignment operator
a *= 2;
printf("After a *= 2 : %d\n", a);
return 0;
}
5. Increment और Decrement Operators
ये operators किसी variable की value को एक से बढ़ाने या घटाने के लिए उपयोग होते हैं।
Increment Operator (++)
- Pre-increment (++a) – पहले value बढ़ाओ, फिर use करो
- Post-increment (a++) – पहले use करो, फिर value बढ़ाओ
Decrement Operator (—)
- Pre-decrement (–a) – पहले value घटाओ, फिर use करो
- Post-decrement (a–) – पहले use करो, फिर value घटाओ
Increment, Decrement Operator Example Code:
#include <stdio.h>
int main() {
int a = 5;
// Post-increment
// First prints the value, then increases it
printf("Post-increment : %d\n", a++);
// Current value of a
printf("Current value of a : %d\n", a);
// Pre-increment
// First increases the value, then prints it
printf("Pre-increment : %d\n", ++a);
return 0;
}
Quiz: ऊपर दिये गए Code में Decrement Operator implement करें, और Output comment box में डालें। ये छोटा सा quize है आपके लिए।
6. Bitwise Operators (Bit-level Operators)
Bitwise operators binary level पर काम करते हैं। ये थोड़े advanced हैं लेकिन system programming में बहुत काम आते हैं। एक beginner के लिए इसे depth में समझना जरुरी नहीं है, इसलिये अभी सिर्फ Basic समझेंगे।
| Operator | मतलब | उदाहरण |
|---|---|---|
| & | Bitwise AND | a & b |
| | | Bitwise OR | a | b |
| ^ | Bitwise XOR | a ^ b |
| ~ | Bitwise NOT | ~a |
| << | Left Shift | a << 2 |
| >> | Right Shift | a >> 2 |
Bitwise Operator Example Code:
#include <stdio.h>
int main() {
int a = 6; // Binary: 0110
int b = 3; // Binary: 0011
// Bitwise AND operation
printf("AND : %d\n", a & b);
// Bitwise OR operation
printf("OR : %d\n", a | b);
// Bitwise XOR operation
printf("XOR : %d\n", a ^ b);
// Left shift operation
printf("Left Shift : %d\n", a << 1);
// Right shift operation
printf("Right Shift : %d\n", a >> 1);
return 0;
}
7. Conditional (Ternary) Operator
यह C का एकमात्र ternary operator है जो तीन operands लेता है। यह if-else का एक छोटा रूप है।
Syntax:
condition ? value_if_true : value_if_false;
Example Code:
#include <stdio.h>
int main() {
int a = 10, b = 20;
int max;
// Using the ternary operator to find the larger number
max = (a > b) ? a : b;
// Printing the larger number
printf("Larger number : %d\n", max);
return 0;
}
यह बहुत उपयोगी operator है, खासकर जब हमें एक line में decision लेना हो।
8. sizeof() Operator
sizeof() operator किसी variable या data type का memory size (bytes में) बताता है, और memory size को print करने के लिये %zu का use करते हैं इस निचे Example Code में %zu का use किया गया है।
Example Code:
#include <stdio.h>
int main() {
// Printing the size of different data types
printf("Size of int : %zu bytes\n", sizeof(int));
printf("Size of char : %zu bytes\n", sizeof(char));
printf("Size of float : %zu bytes\n", sizeof(float));
printf("Size of double : %zu bytes\n", sizeof(double));
return 0;
}
यह operator memory management और array के साथ काम करते समय बहुत उपयोगी होता है।
9. Comma Operator
Comma operator (,) एक से ज्यादा expressions को एक साथ लिखने देता है। यह सबसे ज्यादा for loop में दिखता है।
for (int i = 0, j = 10; i < 5; i++, j–) {
printf(“i=%d, j=%d\n”, i, j);
}
Operators की Precedence (प्राथमिकता)
जब एक expression में कई operators हों, तो कौन सा पहले calculate होगा — यह operator precedence तय करता है।
उदाहरण के लिए:
int result = 10 + 5 * 2; // result = 20, न कि 30
यहाँ * की precedence + से ज्यादा है, इसलिए पहले 5 * 2 = 10 होगा, फिर 10 + 10 = 20।
Precedence का क्रम (ऊपर से नीचे, ज्यादा से कम):
- () – Parentheses (सबसे पहले)
- ++, –, !, ~ – Unary operators
- *, /, % – Multiplication/Division
- +, – – Addition/Subtraction
- <<, >> – Shift operators
- <, <=, >, >= – Relational
- ==, != – Equality
- &, ^, | – Bitwise
- &&, || – Logical
- ?: – Ternary
- =, +=, -= आदि – Assignment
यह Basic Operator और उनके precedence हैं, जो एक Beginner के लिये काफी है। निचे सब operator के precedence के associativity भी दिया गया है जो आगे चलकर आपको बहोत काम आने वाले हैं।
Operator Precedence & Associativity In C – Table
Associativity यह बताती है कि जब दो operators की precedence equal हो, तो expression किस दिशा से evaluate होगा — बाईं से दाईं (Left to Right) या दाईं से बाईं (Right to Left)।
| Precedence | Operators | Associativity | Description |
|---|---|---|---|
| 1 | () [] . -> ++ — (postfix) | Left to Right | सबसे पहले evaluate होते हैं। Function call, array access, struct member access, और postfix increment/decrement। |
| 2 | ++ — + – ! ~ * & (type) sizeof (unary/prefix) | Right to Left | Prefix inc/dec, unary plus/minus, logical NOT (!), bitwise NOT (~), pointer dereference (*), address-of (&), type casting, और sizeof। |
| 3 | * / % | Left to Right | Multiplication, Division, और Modulo (शेषफल)। Addition/Subtraction से पहले calculate होते हैं। |
| 4 | + | – Left to Right | Addition और Subtraction। |
| 5 | << >> | Left to Right | Bitwise Left Shift और Right Shift। Bits को left या right दिशा में खिसकाते हैं। |
| 6 | < <= > >= | Left to Right | Relational operators। दो values की तुलना करते हैं और true/false (1/0) return करते हैं। |
| 7 | == != | Left to Right | Equality check। दोनों values equal हैं या नहीं, यह check करता है। |
| 8 | & | Left to Right | Bitwise AND। दोनों operands के हर bit पर AND operation होता है। |
| 9 | ^ | Left to Right | Bitwise XOR (Exclusive OR)। दोनों bits अलग-अलग हों तभी 1 आता है। |
| 10 | | | Left to Right | Bitwise OR। कोई एक bit 1 हो तो result 1 होता है। |
| 11 | && | Left to Right | Logical AND। दोनों conditions true होनी चाहिए। Short-circuit: पहली condition false हो तो दूसरी check ही नहीं होती। |
| 12 | || | Left to Right | Logical OR। कोई एक condition true हो तो काफी है। Short-circuit: पहली condition true हो तो दूसरी check नहीं होती। |
| 13 | ?: | Right to Left | Ternary operator। एक line का if-else। जैसे: (a > b) ? a : b — condition true हो तो पहली value, false हो तो दूसरी। |
| 14 | = += -= *= /= %= <<= >>= &= ^= |= | Right to Left | Assignment और Compound Assignment। Value assign करना। Right to Left इसलिए क्योंकि a = b = 5 में पहले b = 5 होगा, फिर a = 5। |
| 15 | , | Left to Right | Comma operator। Multiple expressions को sequence में evaluate करता है और आखिरी expression की value return होती है। |
याद रखने योग्य बात: Right to Left associativity सिर्फ तीन cases में होती है — Unary operators, Ternary (?:), और सभी Assignment operators। बाकी सभी operators Left to Right होते हैं।
Conclusion ( निष्कर्ष )
Operator in C in Hindi को समझना C programming की नींव है। इस पोस्ट में हमने Arithmetic से लेकर Bitwise तक, और Ternary से लेकर sizeof तक — सभी जरूरी operators को आसान भाषा में और real code examples के साथ समझा। अगर आप इन सभी operators को अच्छे से practice करें, तो C के loops, functions, और pointers को सीखना आपके लिए बहुत आसान हो जाएगा।
अब आपकी बारी है! हर operator का code अपने computer पर खुद लिखें और run करके देखें — यही सबसे अच्छा तरीका है सीखने का। अगर आपको कोई doubt हो या कोई topic और detail में समझना हो, तो नीचे comment करें। और अगर यह post helpful लगी, तो इसे अपने दोस्तों के साथ जरूर share करें जो C programming सीख रहे हैं।
