C Programming में Operators: Arithmetic, Relational, Logical, Assignment और अन्य सभी Operators को समझें उदाहरणों के साथ

Author: Er. Mujtaba Ansari

अगर आप C Programming सीख रहे हैं, तो Operators को समझना आपके लिए बहुत जरूरी है।
Arithmetic, Relational, Logical और Assignment जैसे Operators C Programming की बुनियाद हैं।
लेकिन क्या आप जानते हैं कि ये Operators वास्तव में कैसे काम करते हैं?
इस Topic में हम C के सभी महत्वपूर्ण Operators को आसान भाषा और उदाहरणों के साथ समझेंगे।
तो चलिए, C Operators को बिल्कुल सरल तरीके से समझते हैं!

📘 Chapter 1: C Programming की मूल बातें
📜 Chapter 2: C Language का इतिहास और विकास
⚙️ Chapter 3: C Compiler को Install करना
💻 Chapter 4: अपना पहला C Program लिखना
🧩 Chapter 5: C Program की संरचना
📦 Chapter 6: Variables और Data Types
🔢 Chapter 7: C में Operators (वर्तमान Chapter)
⌨️ Chapter 8: Input और Output Functions
🔀 Chapter 9: Conditional Statements
🔄 Chapter 10: C में Loops
📊 Chapter 11: Arrays
🔤 Chapter 12: Strings
⚙️ Chapter 13: Functions
👉 Chapter 14: Pointers
🧱 Chapter 15: Structures और Unions
📁 Chapter 16: File Handling

C Programming में Operators क्या होते हैं?

C Programming में Operators ऐसे विशेष चिन्ह या Symbols होते हैं, जिनका उपयोग किसी काम या गणना को करने के लिए किया जाता है।

जिस value या variable पर Operator काम करता है, उसे Operand कहते हैं।

उदाहरण:

A + B

यहाँ:

  • A और BOperands हैं।
  • +Operator है।

C में Operators के प्रकार

  1. Arithmetic Operators – गणितीय काम के लिए
  2. Relational Operators – दो values की तुलना करने के लिए
  3. Assignment Operators – value assign करने के लिए
  4. Conditional Operator – condition के आधार पर value चुनने के लिए
  5. Increment और Decrement Operators – value को 1 बढ़ाने या घटाने के लिए
  6. Logical Operators – एक या अधिक conditions पर काम करने के लिए
  7. Bitwise Operators – bits पर काम करने के लिए
  8. Special Operators – कुछ विशेष कामों के लिए

1. Arithmetic Operators

Arithmetic Operators का उपयोग सामान्य गणितीय कार्य जैसे जोड़ना, घटाना, गुणा और भाग करने के लिए किया जाता है।

Operatorकामउदाहरण
+जोड़नाa + b
-घटानाa - b
*गुणा करनाa * b
/भाग देनाa / b
%शेषफल निकालनाa % b

Addition Operator +

+ Operator का उपयोग दो values को जोड़ने के लिए किया जाता है।

int a = 10;
int b = 20;

int result = a + b;

printf("%d", result);

Output:

30

Subtraction Operator -

- Operator का उपयोग एक value में से दूसरी value घटाने के लिए किया जाता है।

int a = 20;
int b = 10;

printf("%d", a - b);

Output:

10

Multiplication Operator *

* Operator का उपयोग दो values को गुणा करने के लिए किया जाता है।

int a = 5;
int b = 4;

printf("%d", a * b);

Output:

20

Division Operator /

/ Operator का उपयोग एक value को दूसरी value से भाग देने के लिए किया जाता है।

int a = 20;
int b = 5;

printf("%d", a / b);

Output:

4

Modulus Operator %

% Operator भाग देने के बाद बचा हुआ शेषफल (Remainder) बताता है।

int a = 10;
int b = 3;

printf("%d", a % b);

Output:

1

क्योंकि:

10 ÷ 3 = 3
शेषफल = 1

% Operator का उपयोग यह पता लगाने के लिए भी किया जाता है कि कोई संख्या Even या Odd है।

if (number % 2 == 0)
{
    printf("Even");
}

अगर शेषफल 0 है, तो संख्या Even है।

2. Relational Operators

Relational Operators का उपयोग दो values की तुलना (Compare) करने के लिए किया जाता है।

इनका परिणाम सामान्यतः:

  • 1 → True यानी सही
  • 0 → False यानी गलत
Operatorमतलब
==बराबर
!=बराबर नहीं
>से बड़ा
<से छोटा
>=से बड़ा या बराबर
<=से छोटा या बराबर

Equal To ==

int a = 10;
int b = 10;

printf("%d", a == b);

Output:

1

क्योंकि दोनों values बराबर हैं।

Not Equal !=

int a = 10;
int b = 20;

printf("%d", a != b);

Output:

1

क्योंकि दोनों values अलग हैं।

Greater Than >

int a = 20;
int b = 10;

printf("%d", a > b);

Output:

1

क्योंकि 20, 10 से बड़ा है।

Less Than <

int a = 10;
int b = 20;

printf("%d", a < b);

Output:

1

क्योंकि 10, 20 से छोटा है।

Greater Than or Equal To >=

int age = 18;

printf("%d", age >= 18);

Output:

1

क्योंकि age 18 के बराबर है।

Less Than or Equal To <=

int age = 17;

printf("%d", age <= 18);

Output:

1

क्योंकि 17, 18 से छोटा है।

= और == में अंतर

Beginners अक्सर = और == को एक जैसा समझ लेते हैं, लेकिन दोनों का काम अलग है।

= Assignment Operator है

इसका उपयोग किसी variable में value रखने के लिए किया जाता है।

int a = 10;

यहाँ 10 को a में रखा गया है।

== Comparison Operator है

इसका उपयोग दो values को compare करने के लिए किया जाता है।

if (a == 10)

आसान तरीके से याद रखें:

= → Value देता/Assign करता है
== → दो values को Compare करता है

3. Assignment Operators

Assignment Operators का उपयोग किसी variable में value assign या update करने के लिए किया जाता है।

सबसे basic Assignment Operator है:

=

उदाहरण:

int age = 20;

यहाँ 20 को age variable में रखा गया है।

C में कुछ Compound Assignment Operators भी होते हैं:

Operatorउदाहरणइसका मतलब
=a = 10a = 10
+=a += 5a = a + 5
-=a -= 5a = a - 5
*=a *= 5a = a * 5
/=a /= 5a = a / 5
%=a %= 5a = a % 5

उदाहरण:

int a = 10;

a += 5;

printf("%d", a);

Output:

15

क्योंकि:

a += 5

का मतलब है:

a = a + 5

4. Conditional Operator ?:

Conditional Operator को Ternary Operator भी कहा जाता है।

इसका उपयोग किसी simple condition के आधार पर दो values में से एक value चुनने के लिए किया जाता है।

इसमें तीन हिस्से होते हैं:

condition ? expression1 : expression2;

उदाहरण:

int age = 20;

printf("%s", age >= 18 ? "Adult" : "Minor");

Output:

Adult

यहाँ:

age >= 18

condition है।

अगर condition सही है तो Adult मिलेगा, नहीं तो Minor

एक और उदाहरण:

int a = 10;
int b = 20;

int max = (a > b) ? a : b;

printf("%d", max);

Output:

20

5. Increment और Decrement Operators

इन Operators का उपयोग किसी variable की value को 1 बढ़ाने या 1 घटाने के लिए किया जाता है।

Increment ++

Value को 1 बढ़ाता है।

int a = 10;

a++;

printf("%d", a);

Output:

11

यानी:

a++;

के बराबर है:

a = a + 1;

Decrement --

Value को 1 घटाता है।

int a = 10;

a--;

printf("%d", a);

Output:

9

यानी:

a--;

के बराबर है:

a = a - 1;

Pre-Increment और Post-Increment

++ Operator को दो तरह से इस्तेमाल किया जा सकता है:

Pre-Increment

++a;

इसमें value पहले बढ़ती है और फिर इस्तेमाल होती है।

int a = 10;
int b = ++a;

printf("a = %d\n", a);
printf("b = %d", b);

Output:

a = 11
b = 11

Post-Increment

a++;

इसमें value पहले इस्तेमाल होती है और उसके बाद बढ़ती है।

int a = 10;
int b = a++;

printf("a = %d\n", a);
printf("b = %d", b);

Output:

a = 11
b = 10

Prefix और Postfix Operators

प्रकारPrefixPostfix
Increment++AA++
Decrement--AA--

आसान नियम

  • ++A → पहले बढ़ाओ, फिर इस्तेमाल करो
  • A++ → पहले इस्तेमाल करो, फिर बढ़ाओ
  • --A → पहले घटाओ, फिर इस्तेमाल करो
  • A-- → पहले इस्तेमाल करो, फिर घटाओ

Post-Increment का उदाहरण

#include <stdio.h>

int main()
{
    int A = 15, x;

    x = A++;

    printf("x = %d\n", x);
    printf("A = %d\n", A);

    return 0;
}

Output:

x = 15
A = 16

समझिए: A++ में पहले 15 को x में रखा गया और उसके बाद A की value 16 हुई।

Pre-Increment का उदाहरण

#include <stdio.h>

int main()
{
    int A = 9, x;

    x = ++A + 6;

    printf("A = %d\n", A);
    printf("x = %d\n", x);

    return 0;
}

Output:

A = 10
x = 16

समझिए: पहले A की value 9 से 10 हुई। फिर:

10 + 6 = 16

इसलिए x = 16

Post-Increment के साथ Addition

#include <stdio.h>

int main()
{
    int A = 10, x;

    x = A++ + 9;

    printf("x = %d\n", x);
    printf("A = %d\n", A);

    return 0;
}

Output:

x = 19
A = 11

पहले A की वर्तमान value 10 इस्तेमाल हुई:

10 + 9 = 19

फिर A की value 11 हो गई।

एक ही Expression में कई ++ या -- लगाने से बचें

उदाहरण:

int A = 5, x;

x = ++A + A++;

ऐसे code का fixed output बताना सही नहीं है। Standard C में एक ही expression में variable को इस तरह कई बार modify करने पर Undefined Behavior हो सकता है।

इसी तरह:

x = ++A + A++ + ++A + A++ + A;

या:

x = ++A + A++ + A++ + A;

जैसे expressions से beginners को बचना चाहिए।

आसान नियम:

एक ही expression में किसी variable पर कई ++ या -- operations न करें। Code को अलग-अलग statements में लिखना ज्यादा सुरक्षित और आसान है।

if Condition में Post-Increment

यह एक सही उदाहरण है:

#include <stdio.h>

int main()
{
    int A = 9;

    if (A++ >= 10)
    {
        printf("Hi");
    }
    else
    {
        printf("Bye");
    }

    return 0;
}

Output:

Bye

क्यों?

A++ में पहले current value इस्तेमाल होती है।

Current value है:

9

इसलिए condition बनती है:

9 >= 10

यह गलत है, इसलिए else चलेगा:

Bye

इसके बाद A की value 10 हो जाएगी।

Prefix और Postfix का सबसे आसान अंतर

Operatorमतलब
++Aपहले value बढ़ेगी, फिर इस्तेमाल होगी
A++पहले value इस्तेमाल होगी, फिर बढ़ेगी
--Aपहले value घटेगी, फिर इस्तेमाल होगी
A--पहले value इस्तेमाल होगी, फिर घटेगी

Prefix: पहले बदलो, फिर इस्तेमाल करो।
Postfix: पहले इस्तेमाल करो, फिर बदलो।

6. Logical Operators

Logical Operators का उपयोग conditions पर काम करने के लिए किया जाता है।

C में:

  • 0 → False
  • 0 के अलावा कोई भी value → True

मुख्य Logical Operators हैं:

Operatorनाम
&&Logical AND
||Logical OR
!Logical NOT

Truth Table for Logical AND (&&) and Logical OR (||)

┌───────────────────────────────────────┐
│       AND (&&) and OR (||)            │
├─────────┬─────────┬─────────┬─────────┤
│    A    │    B    │ A && B  │ A || B  │
├─────────┼─────────┼─────────┼─────────┤
│    0    │    0    │    0    │    0    │
│    0    │    1    │    0    │    1    │
│    1    │    0    │    0    │    1    │
│    1    │    1    │    1    │    1    │
└─────────┴─────────┴─────────┴─────────┘

Logical AND &&

&& तब 1 देता है जब दोनों conditions True हों।

1 && 1 = 1
1 && 0 = 0
0 && 1 = 0
0 && 0 = 0

आसान नियम:

&& → दोनों conditions सही होनी चाहिए।

Logical OR ||

|| तब 1 देता है जब कम से कम एक condition True हो।

1 || 1 = 1
1 || 0 = 1
0 || 1 = 1
0 || 0 = 0

आसान नियम:

|| → कम से कम एक condition सही होनी चाहिए।

Logical NOT !

! किसी logical value को उलट देता है।

!0 = 1
!1 = 0

आसान नियम:

! → True को False और False को True कर देता है।

याद रखें:

  • && → दोनों सही
  • || → कोई एक सही
  • ! → उल्टा कर देता है

7. Bitwise Operators

Bitwise Operators किसी number के individual bits पर काम करते हैं।

Computer numbers को अंदर से binary form यानी 0 और 1 में रखता है। Bitwise Operators इन्हीं bits पर काम करते हैं।

इनका उपयोग खासकर system programming, embedded systems और low-level programming में किया जाता है।

मुख्य Bitwise Operators

Operatorनामकाम
&Bitwise ANDहर bit पर AND
|Bitwise ORBitwise OR
^Bitwise XORअलग bits पर 1
~Bitwise NOTbits को उलटना
<<Left Shiftbits को left shift करना
>>Right Shiftbits को right shift करना

Bitwise AND &

इसमें result की bit 1 तभी होगी जब दोनों bits 1 हों।

0 & 0 = 0
0 & 1 = 0
1 & 0 = 0
1 & 1 = 1

उदाहरण:

int a = 5;
int b = 3;

printf("%d", a & b);

Binary में:

5 = 0101
3 = 0011
   ----
&  0001

Output:

1

Bitwise OR |

इसमें result की bit 1 होगी अगर कम से कम एक bit 1 हो।

0 | 0 = 0
0 | 1 = 1
1 | 0 = 1
1 | 1 = 1

उदाहरण:

int a = 5;
int b = 3;

printf("%d", a | b);
5 = 0101
3 = 0011
   ----
|  0111

Output:

7

Bitwise XOR ^

XOR में दोनों bits अलग होने पर result 1 होता है।

0 ^ 0 = 0
0 ^ 1 = 1
1 ^ 0 = 1
1 ^ 1 = 0

उदाहरण:

int a = 5;
int b = 3;

printf("%d", a ^ b);
5 = 0101
3 = 0011
   ----
^  0110

Output:

6

Bitwise NOT ~

~ हर bit को उलट देता है:

0 → 1
1 → 0

उदाहरण:

int a = 5;

printf("%d", ~a);

आम तौर पर two’s complement वाले modern systems पर:

~5 = -6

ध्यान दें कि negative values की representation और result platform/type पर निर्भर कर सकते हैं।

Left Shift <<

यह bits को left side में shift करता है।

int a = 5;

printf("%d", a << 1);
5 = 0101
    ↓
   1010

इसलिए:

5 << 1 = 10

Output:

10

Right Shift >>

यह bits को right side में shift करता है।

int a = 8;

printf("%d", a >> 1);
8 = 1000
    ↓
   0100

इसलिए:

8 >> 1 = 4

Output:

4

Bitwise Operators का Quick Revision

&   → Bitwise AND → दोनों bits 1 हों तो 1
|   → Bitwise OR  → कोई एक bit 1 हो तो 1
^   → Bitwise XOR → दोनों bits अलग हों तो 1
~   → Bitwise NOT → bits को उलट देता है
<<  → Left Shift  → bits को left में shift करता है
>>  → Right Shift → bits को right में shift करता है

8. Special Operators

Special Operators का उपयोग C में कुछ विशेष कामों के लिए किया जाता है।

कुछ महत्वपूर्ण Special Operators हैं:

Operatorनामकाम
,Comma Operatorकई expressions को evaluate करना
sizeofSizeof Operatormemory में size पता करना
.Dot Operatorstructure/union member access
&Address-of Operatorvariable का address लेना
*Dereference Operatorpointer के address की value लेना
->Arrow Operatorpointer से structure/union member access

Comma Operator ,

Comma Operator का उपयोग एक expression में कई expressions को evaluate करने के लिए किया जा सकता है।

इसमें expressions left से right evaluate होते हैं और आखिरी expression की value पूरी expression की value बनती है।

उदाहरण:

#include <stdio.h>

int main()
{
    int A;

    A = (2, 4);

    printf("%d", A);

    return 0;
}

Output:

4

यहाँ:

2 → पहले evaluate हुआ
4 → उसके बाद evaluate हुआ

इसलिए आखिरी value 4, A में store हुई।

sizeof Operator

sizeof का उपयोग किसी data type या variable द्वारा कितनी memory इस्तेमाल की जा रही है, यह पता करने के लिए किया जाता है।

यह size bytes में बताता है।

उदाहरण:

printf("%zu", sizeof(int));

कई modern systems पर output:

4

लेकिन यह जरूरी नहीं कि हर system पर int का size 4 bytes ही हो। इसका size system और compiler पर निर्भर करता है।

Variable के साथ:

int a = 10;

printf("%zu", sizeof(a));

String के साथ sizeof

printf("%zu", sizeof("abc"));

Output:

4

क्योंकि "abc" में तीन characters हैं और अंत में \0 भी होता है:

a  b  c  \0

इसलिए कुल size 4 bytes होता है, जब char 1 byte का हो।

Dot Operator .

Dot Operator का उपयोग structure या union के member को access करने के लिए किया जाता है।

उदाहरण:

#include <stdio.h>

struct Student
{
    int age;
};

int main()
{
    struct Student s;

    s.age = 20;

    printf("%d", s.age);

    return 0;
}

Output:

20

यहाँ:

s.age

में . Operator का उपयोग age member को access करने के लिए किया गया है।

आसान नियम:

. → Structure/Union variable के member को access करने के लिए।

Address-of Operator &

& का उपयोग किसी variable का memory address प्राप्त करने के लिए किया जाता है।

उदाहरण:

#include <stdio.h>

int main()
{
    int A = 10;

    printf("%p", (void *)&A);

    return 0;
}

Output में एक memory address आएगा, जैसे:

0x7ffd1234abcd

असल address हर system और program run पर अलग हो सकता है।

& Operator Pointers सीखने में बहुत महत्वपूर्ण है।

Dereference Operator *

* का उपयोग pointer के अंदर मौजूद address पर stored value को access करने के लिए किया जाता है।

उदाहरण:

#include <stdio.h>

int main()
{
    int A = 10;
    int *p = &A;

    printf("%d", *p);

    return 0;
}

Output:

10

यहाँ:

&A → A का address
p  → उस address को store करता है
*p → उस address पर रखी value देता है

ध्यान दें (Note):

* के अलग-अलग context में अलग उपयोग हो सकते हैं।

int *p;

यहाँ * pointer declare करने के लिए है।

जबकि:

*p

यहाँ * dereference operator है।

Arrow Operator ->

Arrow Operator का उपयोग structure या union के member को pointer के माध्यम से access करने के लिए किया जाता है।

उदाहरण:

#include <stdio.h>

struct Student
{
    int age;
};

int main()
{
    struct Student s = {20};
    struct Student *p = &s;

    printf("%d", p->age);

    return 0;
}

Output:

20

यहाँ:

p->age

के द्वारा pointer p से age member को access किया गया है।

इन दोनों का काम समान है:

p->age

और

(*p).age

आसान नियम:

. → Structure variable के member के लिए
-> → Structure pointer के member के लिए

. और -> में अंतर

Operatorकिसके साथ इस्तेमाल होता हैउदाहरण
.Structure/Union variables.age
->Structure/Union pointerp->age

आसान तरीके से:

Structure Variable:
s.age
  ↑
  .
Structure Pointer:
p->age
 ↑
->

Special Operators का Quick Revision

,       → Comma Operator
sizeof  → Size पता करता है
.       → Structure/Union member access
&       → Variable का address
*       → Pointer से value access
->      → Pointer से Structure/Union member access

Operators का पूरा Quick Revision

Operator Typeमुख्य Operatorsमुख्य काम
Arithmetic+ - * / %गणितीय कार्य
Relational== != > < >= <=तुलना करना
Assignment= += -= *= /= %=Value assign/update करना
Conditional?:Condition के आधार पर value चुनना
Increment/Decrement++ --Value को 1 बढ़ाना/घटाना
Logical`&&
Bitwise& | ^ ~ << >>Bits पर काम करना
Special, sizeof . & * ->विशेष कार्य करना

Frequently Asked Questions (FAQs)

1. C में Operators क्या होते हैं?

Operators ऐसे विशेष Symbols हैं जिनका उपयोग values, variables या expressions पर कोई operation करने के लिए किया जाता है।

उदाहरण:

+  -  *  /  ==  &&  =

2. C में Operators कितने प्रकार के होते हैं?

मुख्य रूप से:

  • Arithmetic
  • Relational
  • Assignment
  • Conditional
  • Increment/Decrement
  • Logical
  • Bitwise
  • Special Operators

3. = और == में क्या अंतर है?

= का उपयोग value assign करने के लिए होता है।

int a = 10;

== का उपयोग दो values को compare करने के लिए होता है।

if (a == 10)

4. ++a और a++ में क्या अंतर है?

++a में value पहले बढ़ती है, फिर इस्तेमाल होती है।

a++ में value पहले इस्तेमाल होती है, फिर बढ़ती है।


5. && और & में क्या अंतर है?

&&Logical AND है और conditions पर काम करता है।

&Bitwise AND है और bits पर काम करता है।


6. % Operator का उपयोग किस लिए होता है?

% को Modulus Operator कहते हैं। यह division के बाद बचा हुआ remainder देता है।

int result = 10 % 3;

Result:

1

7. Conditional या Ternary Operator क्या है?

?: को Conditional या Ternary Operator कहते हैं।

यह simple if-else को छोटे रूप में लिखने में मदद करता है।

int max = (a > b) ? a : b;

8. Bitwise Operators क्या होते हैं?

Bitwise Operators numbers की individual bits (0 और 1) पर काम करते हैं।

मुख्य Operators:

&  |  ^  ~  <<  >>

9. sizeof Operator क्या करता है?

sizeof किसी data type या object का size bytes में बताता है।

printf("%zu", sizeof(int));

10. . और -> में क्या अंतर है?

. का उपयोग structure/union variable के member को access करने के लिए होता है।

student.age;

-> का उपयोग structure/union pointer के member को access करने के लिए होता है।

ptr->age;

Top 10 Exam और Interview Questions

1. C में Assignment Operator कौन सा है?

A) ==
B) =
C) !=
D) >=

सही उत्तर: B) =


2. इसका Output क्या होगा?

int a = 5, b = 2;
printf("%d", a + b);

A) 2
B) 3
C) 7
D) 10

सही उत्तर: C) 7


3. C में Modulus Operator कौन सा है?

A) /
B) %
C) //
D) &

सही उत्तर: B) %


4. ++a और a++ में क्या अंतर है?

A) दोनों बिल्कुल समान हैं
B) ++a बाद में increment करता है
C) ++a पहले increment करता है और a++ बाद में
D) दोनों decrement करते हैं

सही उत्तर: C


5. Logical AND Operator कौन सा है?

A) &
B) &&
C) ||
D) !

सही उत्तर: B) &&

ध्यान दें: & Bitwise AND है, जबकि && Logical AND है।


6. इसका Output क्या होगा?

int a = 5, b = 3;
printf("%d", a & b);

A) 1
B) 7
C) 6
D) 8

सही उत्तर: A) 1

क्योंकि:

5 = 0101
3 = 0011
    ----
&   0001

इसलिए result 1 है।


7. किसी variable या data type का size पता करने के लिए कौन सा Operator इस्तेमाल होता है?

A) size()
B) sizeof
C) length()
D) memory()

सही उत्तर: B) sizeof


8. Structure variable के member को access करने के लिए कौन सा Operator इस्तेमाल होता है?

A) ->
B) .
C) *
D) &

सही उत्तर: B) .

उदाहरण:

student.age

9. Structure pointer के member को access करने के लिए कौन सा Operator इस्तेमाल होता है?

A) .
B) &
C) ->
D) ::

सही उत्तर: C) ->

उदाहरण:

ptr->age

10. इसका Output क्या होगा?

int a = 10;
int *p = &a;

printf("%d", *p);

A) a का address
B) 0
C) 10
D) Error

सही उत्तर: C) 10

क्यों?

&a

a का address देता है।

p

उस address को store करता है।

और:

*p

उस address पर मौजूद value को access करता है।

इसलिए output होगा:

10


Leave a Comment

आपका ईमेल पता प्रकाशित नहीं किया जाएगा. आवश्यक फ़ील्ड चिह्नित हैं *