C language me operator kya hai? सभी प्रकार और उदाहरण सहित समझें

C Language me Operator kya hota hai?  Full Beginner Guide

C language में operators वे symbole होते हैं जो variables और values पर कोई operation (क्रिया) करते हैं, जैसे जोड़ना, घटाना, तुलना करना, value assign करना आदि। अगर आप सोच रहे हैं कि C language में operator क्या है (c language me operator kya hai) और ये कैसे काम करते हैं, तो यह लेख आपके लिए है। इस लेख में हम समझेंगे कि C language में operator कितने प्रकार के होते हैं, उनका उपयोग कैसे किया जाता है, और हर प्रकार के operator को उदाहरण के माध्यम से सरल भाषा में समझाया गया है।

Table of Contents

उदाहरण:

यहाँ + एक arithmetic operator है जो a और b को जोड़ता है।

लेकिन c language me operator kya hai ये समझने से पहले हमें constant, expression और operands को समझना पड़ेगा। चलिए, step-by-step समझते हैं।

C language में Constant क्या है ?

Constant वह value (मान) होता है जो बदलता नहीं है जैसे आपने अपने calculator में एक button दबाया 5 यह 5 एक constant है। 

Constant के प्रकार

  • Integer constant : जैसे 5, -20, 100
  • Floating point constant : जैसे  3.5, -0.4, 12.5
  • Character constant : जैसे ‘A’, ‘1’ 
  • String constant : जैसे “Hello”, “World”

C में Operands क्या है ?

Operand वे entities होते है जिन पर कोई operation (क्रिया) किया जाता है अब मान लो आपने calculator में 5 + 3 type किया  तो ये 5 और 3 operand हैं। 

Example : 

इस statement में a और b operand है जिस पर हम जोड़ का operation कर रहे है, और + operator है। 

C language में Expression किसे कहते हैं ? 

Expression वह होता है जो operands  और operators को मिलकर किसी कैलकुलेशन या ऑपरेशन का result देते है। 

Example : 

यहाँ 5 + 3 एक पूरा expression है जो evaluate होकर 8 देगा। 

More example : 

ये सब expression हैं। 

C language में Operators के प्रकार (Types of Operators in C)

C प्रोग्रामिंग में कई तरह के ऑपरेटर होते हैं। नीचे सभी प्रकार के operator और उनका उपयोग example के साथ समझाया गया है। 

  • Arithmetic operator
  • Relational operator
  • Logical operator
  • Assignment operator
  • Bitwise operator
  • increment/ decrement operator
  • Conditional operator
  • Special operator 

1. Arithmetic Operators

ये बेसिक कैलकुलेशन के लिए use होते है , जैसे जोड़, घटाव, गुणा, भाग। जो हम daily लाइफ में इस्तेमाल करते हैं।  

 मान लीजिये  a = 10 और b = 3

Operator symbol काम उदाहरणResult
+जोड़ना (Addition)a + b13
घटाना (Subtraction)a – b7
*गुणा (Multiplication)a * b30
/भाग (Division)a / b3
%शेषफल (Modulus)a % b1

Example:

#include <stdio.h>
// This program performs basic arithmetic operations on two integers
int main() {
int a = 10, b = 3;           //declaring and initializing two variables a and b
printf("Addition (a + b) = %d\n", a + b);        //sum of a and b
printf("subtraction (a - b) = %d\n", a - b);    //subtraction of a and b
printf("multiplication (a * b) = %d\n", a * b); //multiplication of a and b
printf("division (a / b) = %d\n", a / b);        //division of a and b
printf("remainder (a % b) = %d\n", a % b);       //remainder of a and b
    return 0;
}

2. Relational Operators

Relational operator का उपयोग हम दो values की तुलना (comparison) करने के लिए करते हैं, और इसका result true (1) या false (0) के रूप में आता है। ये operator ज़्यादातर if, while, और अन्य conditional statements में condition check करने के लिए उपयोग किए जाते हैं। हम relational operators का उपयोग int, float, char जैसे data types के साथ कर सकते हैं।

मान लीजिये  a = 10 और  b = 3

Operator symbol काम उदाहरणOutput 
==बराबर है ?   (equal to equal)a == b0 (False)
!=बराबर नहीं है ? (not equal)a != b1 (True)
>बड़ा है ?  (greater than)a > b 1 (True)
<छोटा है ? (less than)a < b   0 (False)
>=बड़ा या बराबर है ? (equal or greater than)a >= b  1 (True)
<=छोटा या बराबर है ? (less than or equal)a <= b 0 (False)

Note: Output में 1 का मतलब True (सही) और 0 का मतलब False (गलत) होता है

#include <stdio.h>
// This program performs basic relational operations on two integers.
int main() {
int a = 10, b = 3;           //declaring and initializing two variables a and b
printf("a == b: %d\n", a == b);   // checks if a is equal to b
printf("a != b: %d\n", a != b);   // checks if a is not equal to b
printf("a > b: %d\n", a > b);     // checks if a is greater than b
printf("a < b: %d\n", a < b);     // checks if a is less than b
printf("a >= b: %d\n", a >= b);   // checks if a is greater than or equal to b
printf("a <= b: %d\n", a <= b);   // checks if a is less than or equal to b
    return 0;
}

3. Logical Operators

Logical operator का इस्तेमाल तब करते है जब हम किसी निर्णय (decision) के लिए एक से ज्यादा शर्तों को एक साथ चेक करना होता है। ये operators किसी शर्त का जांच करते हैं  उसका सही (True  1) या गलत (False 0) result देते हैं।  

मान लीजिये a = 10

Operators symbol  कामCondition A              Condition BOutput 
&&AND (दोनों शर्तें सही होनी चाहिये)a  > 5 && a < 201 (True)
| | OR (दोनों में से कोई एक शर्त सही होना चाहिये a > 15 | | a < 251 (True)
!NOT (सही को गलत बनाता है)!(a > 5)0 (False)

Note: Output में 1 का मतलब True (सही) और 0 का मतलब False (गलत) होता है।

Example :

#include <stdio.h>
// This program performs logical operations on two integers.
int main() {
    int a = 5, b = 10;
    printf("Logical AND: %d\n", a && b);    // Logical AND operation
    printf("Logical OR: %d\n", a || b);     // Logical OR operation
    printf("Logical NOT: %d\n", !a);        // Logical NOT operation
    return 0;
}

4. Assignment Operators

Assignment operator variable में वैल्यू assign करने के लिए इस्तेमाल किये जाता है जैसे हम लिखते है a = 30 तो इसका मतलब हम कम्पाइलर को बोल रहे है के a में 30 वैल्यू को assign कर दो। चलिए assignment Operator को एक एक करके समझते है। 

मान लीजिये a = 5  

Operator symbol Meaning (अर्थ)Explanation (व्याख्या)
=Assign करता है (सिर्फ वैल्यू असाइन करता है)a = 5 का मतलब है 5 को a में स्टोर किया गया
+=जोड़कर असाइन करता हैa += 3 का मतलब है a = a + 3, यानी 5 + 3 = 8
-=घटाकर असाइन करता हैअब a = 8 है, a -= 2 का मतलब है a = a – 2, यानी 8 – 2 = 6
*=गुणा करके असाइन करता हैअब a = 6 है, a *= 2 का मतलब है a = a * 2, यानी 6 * 2 = 12
/=भाग देकर असाइन करता हैअब a = 12 है, a /= 4 का मतलब है a = a / 4, यानी 12 / 4 = 3
%=Modulus (शेषफल) निकालकर असाइन करता हैअब a = 3 है, a %= 2 का मतलब है a = a % 2, यानी 3 % 2 = 1

Example:

#include <stdio.h>

int main() {
    int a = 5;  // Initialize variable 'a' with value 5

    // Add 3 to 'a' and assign the result back to 'a'
    // a = a + 3 => a becomes 8
    printf("AAddition assignment (a += 3) = %d\n", a += 3);

    // Subtract 2 from 'a' and assign the result back to 'a'
    // a = a - 2 => a becomes 6
    printf("Subtrction assignment (a -= 2) = %d\n", a -= 2);

    // Multiply 'a' by 2 and assign the result back to 'a'
    // a = a * 2 => a becomes 12
    printf("Multiplication assignment (a *= 2) = %d\n", a *= 2);

    // Divide 'a' by 2 and assign the result back to 'a'
    // a = a / 2 => a becomes 6
    printf("Division assignment (a /= 2) = %d\n", a /= 2);

    // Take remainder when 'a' is divided by 3 and assign back to 'a'
    // a = a % 3 => a becomes 0 (since 6 % 3 = 0)
    printf("Modulus assignment (a %%= 3) = %d\n", a %= 3);

    return 0;  
}

5. Bitwise Operators

Bitwise operator binary (0) और (1) लेवल पे काम करते हैं। इनका use integer वैल्यू के bits पर डायरेक्ट operation करने के लिए होता है। जैसे : 

मान लीजिये

a = 5 binary (0101) और b = 3 binary (0011)

Operator symbol Name (नाम)Meaning (अर्थ)Example (उदाहरण
&ANDदोनों bits 1 हों तभी 1, वरना 0a & b = 5 & 3 → 10101 & 0011 = 0001
ORकिसी एक bit में भी 1 हो तोa | b = 5 | 3 → 7       0101 | 0011 = 0111
^XOR (Exclusive OR)दोनों अलग हों तो 1, एक जैसे हों तो 0a ^ b = 5 ^ 3 →  6         0101 ^ 0011 = 0110
~NOT (Complement)सभी bits को उल्टा कर देता है (1 → 0, 0 → 1), signed numbers में 2’s complement होता है~a = ~5 → -6                ~0101 = 1010 (2’s complement)
<<Left ShiftBits को बाएं शिफ्ट करता है, हर shift पर मान ×2 होता हैa << 1 = 5 << 1 → 10  0101 << 1 = 1010
>>Right ShiftBits को दाएं शिफ्ट करता है, हर shift पर मान ÷2 होता हैa >> 1 = 5 >> 1 → 2 0101 >> 1 = 0010

Note :अगर आप अभी C language सीखना शुरू कर रहे हैं, तो सिर्फ bitwise operator का basic concept समझना ही काफ़ी है। इनका उपयोग थोड़ा advanced होता है, इसलिए हम इसे detail में किसी और Post में समझेंगे।  फिर भी निचे दिए गए कोड को कॉपी करके अपने Code editor में run करके देखें idea मिलेगा कि ये operator काम कैसे करते हैं। 

Example :

#include <stdio.h>

int main() {
    int a = 5;     // Binary: 0101
    int b = 3;     // Binary: 0011

    printf("a & b = %d\n", a & b);   // AND operator
    printf("a | b = %d\n", a | b);   // OR operator
    printf("a ^ b = %d\n", a ^ b);   // XOR operator
    printf("~a = %d\n", ~a);         // NOT operator (1's complement of a)
    printf("a << 1 = %d\n", a << 1); // Left shift
    printf("a >> 1 = %d\n", a >> 1); // Right shift

    return 0;
}

5. Increment & Decrement Operators (बढ़ाने और घटाने वाले ऑपरेटर)

C Language में increment और decrement operator का उपयोग variable की value को 1 से बढ़ाने या घटाने के लिए किया जाता है।

++  Increment Operator: एक value को 1 से बढ़ाता है

  Decrement Operator: एक value को 1 से घटाता है

ये दोनों operator सिर्फ integers, characters, और pointers पर लागू होते हैं।

Increment और Decrement operator 2 तरीके से use किये जाते है। 

  1. Prefix Form (++a, –a)

Operator पहले आता है, फिर value में बदलाव होता है।

  1. Postfix Form (a++, a–)

Operator बाद में आता है, पहले पुरानी value use होती है, फिर increment/decrement होता है।

Example Code:

#include <stdio.h>

int main() {
    int a = 5;  // Initialize variable 'a' with value 5

    a++;  // Post-increment: 'a' is increased by 1 (a becomes 6)
    printf("The value of a is after post-increment: %d\n", a);

    ++a;  // Pre-increment: 'a' is again increased by 1 (a becomes 7)
    printf("The value of a is after pre-increment: %d\n", a);

    a--;  // Post-decrement: 'a' is decreased by 1 (a becomes 6)
    printf("The value of a is after post-decrement: %d\n", a);

    --a;  // Pre-decrement: 'a' is again decreased by 1 (a becomes 5)
    printf("The value of a is after pre-decrement: %d\n", a);

    return 0;
}

7. Conditional Operator (Ternary Operator / संविधिक ऑपरेटर)

Conditional Operator को Ternary Operator भी कहा जाता है, क्योंकि यह तीन हिस्सों में काम करता है। आमतौर पर, इसका इस्तेमाल तब किया जाता है जब हमें किसी condition का जवाब एक ही लाइन में देना हो। यह इसलिए उपयोगी होता है क्योंकि यह बिल्कुल if-else की तरह काम करता है, लेकिन इसके मुकाबले छोटा और तेज़ तरीका होता है।

अगर आपको if-else अभी नहीं आता, तो घबराने की जरूरत नहीं है।
अगले ब्लॉग में, हम इसे भी आसान भाषा में step-by-step समझाएंगे।

Syntax:

(condition) ? value_if_true : value_if_false;

PartExplanation (मतलब)
conditionकोई भी logical expression (e.g. a > b)
value_if_trueअगर condition सही है तो ये execute होगा
value_if_falseअगर condition गलत है तो ये execute होगा

Example :

#include <stdio.h>  

int main() {
    int a = 12;  // Initialize variable 'a' with value 12

    // Use ternary operator to check if 'a' is greater than 10
    // If condition (a > 10) is true, it will print "a is greater than 10"
    // Otherwise, it will print "a is not greater than 10"
    (a > 10) ? printf("a is greater than 10\n") : printf("a is not greater than 10\n");

    return 0;  
}

8. Special Operators (विशेष ऑपरेटर)

Special Operators वो ऑपरेटर होते हैं जो C language में कुछ special या advanced काम करने के लिए इस्तेमाल होते हैं — जैसे किसी variable का memory address लेना, pointer को handle करना, या size निकालना।

ये normal mathematical या logical काम नहीं करते, बल्कि program के अंदर data structure और memory से जुड़ा काम करते हैं।

मुख्य Special Operators in C

  • sizeof: किसी वैरिएबल या डेटा टाइप का साइज़ बताने के लिए
  • &: address-of operator – किसी वैरिएबल का एड्रेस देता है
  • *: pointer dereference – पॉइंटर की वैल्यू एक्सेस करता है

1. sizeof Operator

इसका उपयोग किसी variable या data type का size (byte में) पता करने के लिए होता है।

syntax :

sizeof(datatype or variable);

Example:

#include <stdio.h>

int main() {
    int a;
    float b;
    double c;
    char d;

    // sizeof operator gives the size (in bytes) of a data type or variable

    printf("Size of int: %lu bytes\n", sizeof(a));       // typically 4 bytes
    printf("Size of float: %lu bytes\n", sizeof(b));     // typically 4 bytes
    printf("Size of double: %lu bytes\n", sizeof(c));    // typically 8 bytes
    printf("Size of char: %lu bytes\n", sizeof(d));      // always 1 byte

    // Using sizeof with data types directly
    printf("Size of long long: %lu bytes\n", sizeof(long long));

    return 0;
}

Note: %lu format specifier है जो unsigned long integer प्रिंट करने के लिए इस्तेमाल किया जाता है।

2. & Operator – Address-of Operator

ये operator किसी variable का memory address return करता है।

Syntax:

&variable_name

Example:

#include <stdio.h>

int main() {
    int a = 10;  // Declare an integer variable 'a' and assign value 10

    // Print the value of 'a'
    printf("Value of a: %d\n", a);

    // Use address-of operator '&' to print the memory address of 'a'
    printf("Address of a: %p\n", &a);  // %p is used for printing address (pointer format)

    return 0;
}

3. * Operator – Pointer (Dereference) Operator

ये operator pointer variable के ज़रिए actual value access करने के लिए होता है।

आगे चलके पॉइंटर हम समझने वाले है अभी के लिए इतना जानिए के ये भी एक ऑपरेटर है।

Syntax:

*pointer_variable

Example:

#include <stdio.h>

int main() {
    int a = 10;         // Declare a variable 'a'
    int *ptr = &a;      // Declare a pointer and store address of 'a' using &

    // Using * to dereference pointer and access the value stored at that address
    printf("Value of a using pointer: %d\n", *ptr);     // Output: 10
    printf("Address stored in pointer: %p\n", ptr);     // Address of 'a'
    printf("Value of a directly: %d\n", a);             // Also 10

    return 0;
}

चलिए अब Operator Precedence को पढ़ते हैं।

8. C language में operator precedence

C language में जब आप एक ही लाइन में कई operators का इस्तेमाल करते हो, तो ये जानना ज़रूरी होता है कि कौन-सा operator पहले चलेगा। इसे ही precedence (प्राथमिकता) कहते हैं।

अगर दो operators की priority बराबर होती है, तो associativity ये तय करता है कि कौन-सा पहले चलेगा – left से right या right से left

Why is it important? (ज़रूरी क्यों है?)

अगर आप precedence नहीं समझते, तो आपका result गलत आ सकता है:

उदाहरण:

int y = (10 + 5) * 2;  // ब्रैकेट की वजह से: 30

int x = 10 + 5 * 2;  // यहाँ पहले 5 * 2 होगा, फिर 10 + 10 = 20

Associativity kya hoti hai?

अगर दो operator की precedence same हो — जैसे + और – तो compiler decide करता है कि left से right चलेगा या right से left

उदाहरण:

int x = 10 – 5 + 2;

  • यहाँ – और + की precedence same है
  • Associativity left-to-right है

इसलिए execution: (10 – 5) + 2 = 7

Real-life Example:

int a = 5, b = 10, result;

result = a + b * 2 > 20 || a == 5;

इसमें कौन सा operator पहले चलेगा?

* (Multiplication) – सबसे पहले

फिर +

फिर >

फिर ==

फिर ||

Execution Order:

result = (a + (b * 2) > 20) || (a == 5);

Result = 1 आएगा।

 नीचे टेबल में Operator और उसके precedence level, Associativity दिया गया है। 

C Language में Operator Precedence और Associativity

Precedence LevelOperator(s)DescriptionAssociativity
1  (Highest)()ParenthesesLeft to Right
2++, , +, , !, ~Unary operatorsRight to Left
3*, /, %Multiplication, Division, ModulusLeft to Right
4+, Addition, SubtractionLeft to Right
5<, <=, >, >=Relational operatorsLeft to Right
6==, !=EqualityLeft to Right
7&Bitwise ANDLeft to Right
8^Bitwise XORLeft to Right
9|Bitwise ORLeft to Right
10&&Logical ANDLeft to Right
11?:Ternary (Conditional)Right to Left
12=, +=, -=, *=, etc.Assignment OperatorsRight to Left
13,Comma OperatorLeft to Right

निष्कर्ष (Conclusion)

C Language में Operators एक core हिस्सा हैं, क्योंकि यही symbols हैं जो variables और values पर action लेते हैं — जैसे जोड़ना, तुलना करना, वैल्यू assign करना आदि। इस लेख में आपने जाना:

  • Operands और Expression क्या होते हैं
  • C के सभी 8 प्रकार के Operators
  • Precedence और Associativity का logic
  • हर एक Operator का उपयोग Examples और Code snippets से

अगर आप beginner हैं, तो सबसे पहले arithmetic, relational और assignment operators पर फोकस करें। Bitwise और special operators थोड़ा advance होते हैं लेकिन इनका overview समझना ज़रूरी है ताकि जब pointers और memory से जुड़ी चीज़ें आएं तो confusion न हो।

C में mastery पाने के लिए practice ज़रूरी है – जितना ज़्यादा खुद से code लिखोगे, उतनी जल्दी ये concepts clear होंगे।

अक्सर पूछे जाने वाले सवाल (FAQs)

Q1: क्या C में सभी Operators एक जैसे काम करते हैं जैसे Maths में करते हैं?

नहीं। कई Operators जैसे /, %, और ++ का behaviour Maths से अलग हो सकता है। इसलिए C में उनके काम करने का तरीका और precedence rules समझना ज़रूरी होता है।

Q2: अगर एक ही लाइन में कई operator हों, तो कैसे decide करें कौन-सा पहले चलेगा?

इसका जवाब है: Operator Precedence और Associativity. हर operator की एक priority होती है और अगर दो operators की priority बराबर है, तो associativity तय करता है कि कौन पहले चलेगा – left से या right से।

Q3: क्या मैं एक से ज्यादा operators एक ही लाइन में use कर सकता हूँ?

हाँ, बिलकुल! लेकिन caution के साथ। अगर precedence और associativity का ध्यान नहीं रखा गया, तो गलत result आ सकता है। जरूरत हो तो brackets () का use करें।

Q4: क्या Bitwise Operators Beginners के लिए जरूरी हैं?

ज़रूरी तो हैं, लेकिन basic understanding काफी है शुरुआत में। जैसे-जैसे आप advanced topics जैसे pointers और embedded systems पढ़ेंगे, तब इनका use ज़्यादा आएगा।

Q5: Conditional (Ternary) Operator का फायदा क्या है?

आप ये पोस्ट्स भी पढ़ सकते हैं:

Leave a Comment

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

Scroll to Top