What is Operators in C - C में Operators क्या है

Operators वास्तव मे Symbols होते है
जिसका Use हम अपने Program में Arithmetic और Logical Operations को Perform कराने के लिए करते 

जब भी हम Operator का Use करते है तब हम Complier को यह instruction देते है कि हमे Data के साथ यह कार्य करवाना है।
दूसरे शब्दों में कहें तो ऐसे Symbol जिसका प्रयोग Complier को
 Mathematical और Logical Operations को Perform करने के लिए कहे Operators कहलाता है
Example:
6+8 = 14

ऊपर के Example में + और =  चिन्ह Operators है तथा 6 और 8 Operands है जिस पर Addition Operations किया गया है और Result 14 प्राप्त हुआ है

Types of Operators in C in Hindi- C में Operators के प्रकार


C में Operators के निम्न प्रकार है
1) Arithmetic Operators
2) Relational Operators
3)Logical Operations
4) Assignment Operators
5) Bitwise Operators
7) Increment and Decrement Operators
8) Misc Operarators

Arithmetic Operators

Arithmetic Operators का Use Operands पर Arithemetic या Mathematical Operations Perform करने के लिए किया जाता है

सरल शब्दों मे कहे तो ऐसा Operators जिनका प्रयोग गणित के कार्यों जैसे जोड़ना, घटाना, गुणा करना आदि  में होता है Arithmetic Operators कहलाता है

Arithmetic Operators
Operator Description Example
+ Addition 6 + 4 = 10
- Subtraction 7 - 4 = 3
* Multiplication 3 * 2 = 6
/ Division 16 / 2 = 8
% Modulus 13 % 3 = 1


Program for Arithmetic Operators
#include <stdio.h> 
int main()
 {
    int x = 10, y = 4;
    int sum = x + y;
    int sub = x - y;
    int multi = x * y;
    int division = x / y;
    int remainder = x % y;

    printf("x+y is = %d\n", sum);
    printf("x-y is = %d\n", sub);
    printf("x*y is = %d\n", multi);
    printf("x/y is = %d\n", division);
    printf("x%y is = %d\n", remainder);
    return 0;
}
 
Output:
x+y is = 14
x-y is = 6
x*y is = 40
x/y is = 2
x%y is = 2

Relational Operators

Relational Operators का Use दो Values या Operands की तुलना करने तथा उनके बीच Relationship की जांच करने के लिए होता है जैसे एक

Operand की Value दूसरे Operand के बराबर है या नहीं अथवा क्या एक Operand की Value दूसरे Operand की Value से बड़ी है या छोटी है आदि कार्यों हेतु इस Operators का प्रयोग किया जाता है 

ये Binary Operators है तथा Result को Boolean Values के रूप में Return करते है यदि Relation True है तो Result 1 होगा और Relation False है तो Result 0 होगा ये Operators सामान्यत: Conditional Statements और Looping में Use किए जाते है

Relational Operators
Operator Description Example
== Equal to 7 == 7
!= Not equal to 6 != 4
> Greater than 8 > 5
< Less than 2 < 6
>= Greater than or equal to 6 >= 6
<= Less than or equal to 4 <= 6
Program for Relational Operators
#include <stdio.h> 
int main() 
{
    int a = 7, b = 15;
    if (a < b)
     {
        printf("a is less than b\n");
      }
    if (a <= b) {
        printf("a is less than or equal to b\n");
    }
    if (a > b) {
        printf("a is greater than b\n");
    }
    if (a >= b) {
        printf("a is greater than or equal to b\n");
    }
    if (a == b) {
        printf("a is equal to b\n");
    }
    if (a != b) {
        printf("a is not equal to b\n");
    }
    return 0;
}
 
Output:
a is less than b
a is less than or equal to b
a is not equal to b

ऊपर वही Output प्रदर्शित होगा जिसके लिए Condition True है और जो Condition को पूरा नही कर पा रहे है वह Output प्रदर्शित नही होगा

Logical Operators

Logical Operators कर Use boolean Values या दिए गए Expression में Logical Operations Perform करने के लिए किया जाता है

ये Operators आपको कई Conditions को मिलाने और उसे एक Single Expression में मूल्यांकित करने की अनुमति देते है

Logical operators को सामान्यत: Relational Operators के साथ Use करके Control flow Statements जैसे if statements, loops और switch statements में जटिल Conditions का निर्माण किया जाता है  

Logical Operators
Operator Description Example
Logical AND यदि दोनो operands true है तो ही true return होगा नही तो false return होगा यदि उनमें से केवल एक ही operand true है तो (x && y)
Logical OR
यदि कोई भी एक operand true है तो true return होगा और दोनो operands false है तभी false return होगा
(x || y)
Logical NOT
यह operand की Value को Negates कर देता है
(!x)

Program for Logical Operators
#include <stdio.h>
int main()
{
int a = 5, b = 11, c = 20;

// Using && (logical AND) operator
if (a > 10 && b > 10)
       {
printf("Both a and b are greater than 10 .\n");
       }

// Using || (logical OR) operator
    if (a < 10 || b<10)
     {
printf("One of the two is less than atleast.\n");
     }  
  
// Using ! (logical NOT) operator
    if (!(c==10))
     {
printf("C is not equal to 10.\n");
}
return 0; }

Output:
One of the two is greater than atleast.
C is not equal to 10.

ऊपर के Program में जो Condition True होगा वहीं Statements Print होगा

Assignment Operators

Assignment Operators का प्रयोग Variable को Value Assign करने के लिए किया जाता है

सबसे ज्यादा Use होने वाला Operator बराबर (=) है जिसका कार्य Right Side में उपस्थित Value को,  Operator के Left Side में उपस्थित Variable को Assign करना है

Assignment Operator को अन्य Operators के साथ Use करके एक ही Statement में  जटिल Operations Perform कर सकते है

Program for Assignment Operators
#include<stdio.h> 

int main() {
    int x = 15, y = 5;   
    
 // Using all Assignment operators
    x += y;  // Similar to x = x + y;
    printf("Result of x += y is: %d\n", x);
    
    
    x -= y;  // Similar to x = y - y;
    printf("Result of x -= y is: %d\n", x);
    
    
    x *= y;  // Similar to x = x * y;
    printf("Result of x *= y is: %d\n", x);
    
    
    x /= y;  // Similar to x = x / y;
    printf("Result of x /= y is: %d\n", x);
    
    
    x %= y;  // Similar to x = x % y;
    printf("Result of x %%= y is: %d\n", x);    
    return 0;
}
Output:
Result of x += y is: 20
Result of x -= y is: 15
Result of x *= y is: 75
Result of x /= y is: 15
Result of x %= y is: 0

Bitwise Operators

Memory में Data को Binary form अर्थात 0 या 1 में Store किया जाता है कभी कभी हमें इन bits को परिवर्तित करने की आवश्यकता होती है अतः इन bits को परिवर्तित करने के लिए जिन Operators का Use किया जाता है उसे Bitwise Operators कहते है

Bitwise operators का Use अक्सर low-level programming, device drivers, और embedded systems में किया जाता है क्योंकि यहां पर किसी कार्य को करने या Hardware Interaction के लिए सीधे ही bits को manipulate की जरुरत होती है 

Bitwise Operators
Operator Description Example
& Bitwise AND a & b
| Bitwise OR a | b
^ Bitwise XOR a ^ b
~ Bitwise NOT ~a
<< Left shift a << n
>> Right shift a >> n


Program for Bitwise Operators
#include <stdio.h> 
int main() {
    int a = 10; // Binary form:1010 
    int b = 5;  // Binary form :0101 
 
    // Bitwise AND
    int AND_result = a & b;
    printf("Result of Bitwise AND: %d\n", AND_result);

    // Bitwise OR
  int OR_result = a | b;
    printf("Result of Bitwise OR: %d\n", OR_result);

    // Bitwise XOR
    int XOR_result = a ^ b;
    printf("Result of Bitwise XOR: %d\n", XOR_result);

    // Bitwise left shift
    int Lshift_result = a << 2;
    printf("Result of Bitwise Left Shift: %d\n", Lshift_result);

    // Bitwise right shift
  int Rshift_result = a >> 2;
    printf("Result of Bitwise Right Shift: %d\n", Rshift_result);
    return 0;
}
 
Output:
Result of Bitwise AND: 0
Result of Bitwise OR: 15
Result of Bitwise XOR: 15
Result of Bitwise Left Shift: 40
Result of Bitwise Right Shift: 2

Increment and Decrement Operators

C Programming में, Increment और Decrement Operators Unary Operator है अर्थात इनमे एक ही Operand होते है।

इन Operators का Use एक Variable की Value में 1 बढ़ाने या घटाने के लिए किया जाता है

जब हम Increment Operator (++) Use करते है तब यह Value में एक बढ़ा देता है और जब हम Decrement Operator (++) Use करते है तब यह Value में एक घटा देता  है

Types of Increment Operator in C
Increment Operators दो प्रकार के होते है
1) Post-Increment Operator
2) Pre-Increment Operator

1) Post-Increment Operator
यदि Increment Operator को Operand के बाद लगाया जाए तो यह Post Increment Operator कहलाता है जिसमे पहले Operand की Value का प्रयोग किया जाता है उसके बाद उसमे Increment होता है
Example
int a = 10;
result = a++;

ऊपर का Expression निम्न प्रकार से कार्य करेगा
result = a;
a = a+1;

पहले a की Value 10 Print होगी उसके बाद उसमे Increment Operator द्वारा 1 बढ़ाया जायेगा

2) Pre Increment Operator
यदि Increment Operator को Operand के पहले लगाया जाए तो यह Pre Increment Operator कहलाता है जिसमे पहले Operand की Value में Increment होगा तब उस Operand का प्रयोग किया जायेगा है 
Example:
int a = 10;
result = ++a;

ऊपर का Expression निम्न प्रकार से कार्य करेगा
a = a+1;
result = a;

पहले a की Value 10 में 1 Increment होकर 11 Print होगी उसके बाद उस Operand को Use किया जायेगा

Program for Post and Pre Increment Operators 
#include<stdio.h> 
int main() {
   int a = 10;
   int b = 10;
//Using Post-Increment operator
    int result1 = a++;
    printf("After Using Post-Increment Operator: %d\n", result1);

//Using Pre-Increment operator
    int result2= ++b;
    printf("After Using Pre-Increment Operator: %d\n", result2);
return 0;
}
 

Output:
After Using Post-Increment Operator: 10
After Using Pre-Increment Operator: 11

Types of Decrement Operator in C 
Decrement Operators दो प्रकार के होते है
1) Post- Decrement Operator
2) Pre-Decrement Operator

1) Post-Decrement Operator
यदि Decrement Operator (- -) को Variable के बाद लगाया जाए तो Operator Post -Decrement Operator होगा इसमें Operand की Value का Use होने के बाद 1 घटाया जायेगा
Example
int a = 10;
result = a--;

ऊपर का Expression निम्न प्रकार से कार्य करेगा
result = a;
a = a-1;

पहले a की Value 10 Print होगी उसके बाद उसमे Decrement Operator द्वारा 1 घटाया जायेगा

2) Pre-Decrement Operator
यदि Decrement Operator (- -) को Variable के पहले लगाया जाए तो वह Operator Pre -Decrement Operator कहलाएगा इसमें Operand की Value को Use होने के पहले उसमे 1 घटाया जायेगा
Example
int a = 10;
result = --a;

ऊपर का Expression निम्न प्रकार से कार्य करेगा
a = a-1;
result = a;

पहले a की Value अर्थात 10 में Decrement Operator द्वारा 1 घटाया जायेगा तब उसकी Value 9 Print होगी 


Program for Post and Pre Decrement Operators
#include<stdio.h> 
int main() 
 {
         int x = 12;
         int y = 12;
      // Using Post-Decrement operators
   int result1=x--;
    printf("After Using Post-Decrement Operator: %d\n", result1);

   // Using Pre-Decrement operators
int result2= --y;
    printf("After Using Pre-Decrement Operator: %d\n", result2);
return 0;
}
 

Output:
After Using Post-Decrement Operator: 12
After Using Pre-Decrement Operator: 11

Misc Operators or Other Operator

ऊपर दिए Operators के अतिरिक्त C में कुछ अन्य Operators भी होते है जिन्हे अलग अलग कार्यों के लिए Use किया जाता है।
ये Operators निम्न है
I) sizeof Operator
sizeof operator का Use एक Variable या Data Type के Size को bytes में return करने के लिए किया जाता है 

अर्थात एक Variable ने Memory में कितना स्थान घेरा है उसके bytes की संख्या कितनी है यह पता लगाने के लिए किया जाता है
   Example:
   int a = sizeof(int); 

ऊपर a मे interger Value Store होगा और यह Interger Value Memory में 4 bytes जगह लेगा

II) Comma Operator
Comma operator का Use Statements या Expression को अलग करने के लिए किया जाता है

जब हम दो से अधिक Statements को जोड़कर एक Statements बनाना चाहते है तो इस Operator का प्रयोग करते हैं इस प्रकार हम जटिल Statements का निर्माण कर सकते हैं Statements का execution एक एक करके Left से Right Side में होता है
 Example:
int a = 41, b = 20, c = 13;

III) Conditional Operator
Conditional Operator को Ternary Operator के नाम से भी जाना जाता है जैसे कि इसके नाम से ही पता चलता है कि यह Operator तीन Operands पर कार्य करता है

यह Operator Condition की जांच करता है और Condition के True या False होने की स्थिति में Value Return करता है
   Example:
   int a = 15, b = 43;
   int result = (a > b) ? a : b; 

// Output b = 43
   
IV) Address-of Operator (&):
C programming language में Address operator (&) एक unary operator है जिसका Use किसी Variable के memory address को प्राप्त करने मे होता है.

 Address operator का Use करना कुछ कार्यों जैसे Argument को reference के द्वारा Pass करते समय, dynamic memory allocation और hardware को सीधे ही Access करने हेतु आवश्यक है 
Example:
   int a = 6;
   int *ptr = &a; 

ऊपर Example में *ptr में a Variable का Address है

V) Pointer Operator (*):
C programming language में, pointer operator को asterisk symbol (*), के द्वारा Represent किया जाता है जिसका Use Pointer को Declare करने और उसके साथ कार्य करने मे होता है

वास्तव में Pointers,  Variables होते है जो Memory Addresses को Store करते है जो आपको Memory में Store Data को Indirect रूप से Access करने और उसमें हेरफेर करने की अनुमति देते है
Example:
 int num = 6;
 int* ptr;
 ptr = &num;

पहले लाइन में num नाम से Variable Declare किया गया है दूसरे लाइन मे एक Integer Pointer (*ptr) Declare किया गया है और तीसरे लाइन मे num Variable के Memory Address को ptr, Pointer को Assign किया गया है


 Related Post