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

C++ में Operators, Symbols होते है जो Variables या Values पर विशेष कार्य जैसे Arithmetic calculations करना, Values को Compare करना या Variables के State(अवस्था) को बदलना जैसे कार्य करते हैं।
इन कार्यों मे Addition, Substraction, Multiplication, Division, Assignment, Comparison और Logical Operations शामिल होते है।

C++ में Operators, Data को Manipulate करने और Program के flow को Control करने के लिए आवश्यक होते है जो Developers को संक्षिप्त और कुशल Code लिखते मे सक्षम बनाते है

दूसरे शब्दों में कहें तो ऐसे Symbol जिसका प्रयोग Complier को Mathematical और Logical Operations को Perform करने के लिए कहे Operators कहलाता है
Example:
2+3 = 5

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


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 Operators

Arithmetic Operator

C++ में Arithmetic Operators ऐसे Symbols है जिसका Use Numeric operands पर Mathematical operations Perform करने के लिए किया जाता है

ये Operators C++ में Integer, floating- point, numbers, और अन्य Numeric Data types के साथ Basic calculation करने के लिए Use किए जाते है जो उन्हें Numerical operations के लिए fundamental tools बनाते है

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


Arithmetic Operators
Operator Description Example
+ Addition 2 + 3 = 5
- Subtraction 8 - 4 = 4
* Multiplication 4 * 3 = 12
/ Division 14 / 2 = 7
% Modulus 13 %4  = 1


Program for Arithmetic Operators
      
#include<iostream>
using namespace std;
int main()
 {
    int x = 15, y = 5;
    int sum = x + y;
    int sub = x - y;
    int multi = x * y;
    int division = x / y;
    int remainder = x % y;

cout<<"Result of x+y is: "<< sum<<endl;
cout<<"Result of x-y is: "<< sub<<endl;
cout<<"Result of x*y is: "<<multi<<endl;
cout<<"Result of x/y is: "<<division<<endl;
cout<<"Result of x%y is: "<<remainder<<endl;
    return 0;
}
 
Output:
Result of x+y is: 20 
Result of x-y is: 10 
Result of x*y is: 75
Result of x/y is: 3 
Result of x%y is: 0

Relational Operators

C++ में Relational Operators का Use Values की तुलना करने तथा उनके बीच Relationship को निर्धारित करने के लिए होता है 

ये Operators, condition के आधार पर Value की तुलना करने और Program के flow को नियंत्रित करने के लिए महत्त्वपूर्ण भूमिका निभाते है

ये Program में Decision लेने के लिए सुविधाजनक है जब हम उसे Use करते है तब हमे यह एक Simple answer, true या false के रूप में देते है जो कि एक Boolean value है

इसलिए यदि आप आपने Program में Numbers या Data की तुलना करना चाहते है तो ये Operators आपको ऐसा करने में मदद करते है

Relational Operators
Operator Description Example
== Equal to 5== 5
!= Not equal to 7!= 5
> Greater than 9 > 7
< Less than 3<7
>= Greater than or equal to 4 >= 4
<= Less than or equal to  3<= 4

Program for Relational Operators
#include <iostream> 
using namespace std;
int main() 
{
    int a = 5, b = 17;
    if (a < b)
          {
    cout<<"a is less than b"<<endl;
          }
    if (a <= b) 
        {
     cout<<"a is less than or equal to b"<<endl;
         }
    if (a > b)
        {
    cout<<"a is greater than b"<<endl;
        }
    if (a >= b) 
       {
    cout<<"a is greater than or equal to b "<<endl;
        }
    if (a == b) 
       {
    cout<<"a is equal to b "<<endl;
        }
    if (a != b)
       {
    cout<<"a is not equal to b"<<endl;
      }
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

C++ में Logical Operators कर Use Boolean expression को Combine या Manipulate करने के लिए किया जाता है

ये Operators आपको कई Conditions के आधार पर Program के flow को Control करने के लिए महत्त्वपूर्ण है.
ये सरल Conditions को जोड़कर जटिल Conditions का निर्माण करने में सहायक है 

तथा कुशल और मजबूत C++programs बनाने के लिए Decision making, loop control और Conditional statements में बड़े पैमाने पर Use किए जाते है

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<iostream>
using namespace std;
int main()
{
int a = 3, b = 7, c = 12;

// Using && (logical AND) operator
if (a > 10 && b > 10)
       {
 cout<<"Both a and b are greater than 10"<<endl;
       }

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

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

Assignment Operators

C++ में Assignment Operators का प्रयोग Variable को Value Assign करने के लिए किया जाता है
यह Value को Right side से लेता है और उसे Left side के Variable में Store कर देता है

उदाहरण के लिए "x = 10"; है इसका अर्थ Variable x को 10 value Assign करना

ये Operators, Program execution के दौरान Variables को Initialize करने और उनके Values को Update करने के लिए आधारभूत है

इस Operators का Use करके, Programmers, Variables को Value Assign कर सकते है, Data को Dynamically Store और Manipulate कर सकते हैं

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

Program for Assignment Operators
#include<iostream> 
using namespace std;
int main() 
 {
    int x = 15, y = 5;   
    
 // Using all Assignment operators
    x += y;  // Similar to x = x + y;
 cout<<"Result of x += y is:"<<x<<endl;
    
    
    x -= y;  // Similar to x = x - y;
 cout<<"Result of x -= y is:"<<x<<endl;
    
    
    x *= y;  // Similar to x = x * y;
 cout<<"Result of x *= y is:"<<x<<endl;
    
    
    x /= y;  // Similar to x = x / y;
 cout<<"Result of x /= y is:"<<x<<endl;
    
    
    x %= y;  // Similar to x = x % y;
 cout<<"Result of x %= y is:"<<x<<endl;    
    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

C++ में Bitwise operators, Numbers के छोटे भागो, जिन्हे "Bits" कहा जाता है, के साथ कार्य करते है 

Computer 0s और 1s में सबकुछ समझते हैं और ये Operator आपको इन 0s और 1s के साथ सीधे ही कार्य करने की अनुमति देते हैं आप कुछ bits को on या off कर सकते है, उसे हटा सकते हैं या यह जांच सकते है कि वे Set है या नहीं

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<iostream>
using namespace std;
int main()
{
int a = 10; // Binary form:1010 int b = 5; // Binary form :0101 // Bitwise AND int AND_result = a & b; cout<<"Result of Bitwise AND: "<< AND_result<<endl; // Bitwise OR int OR_result = a | b; cout<<"Result of Bitwise OR:"<<OR_result<<endl; // Bitwise XOR int XOR_result = a ^ b; cout<<"Result of Bitwise XOR:"<<XOR_result<<endl; // Bitwise left shift int Lshift_result = a << 2; cout<<"Result of Bitwise Left Shift: "<<Lshift_result<<endl; // Bitwise right shift int Rshift_result = a >> 2; cout<<"Result of Bitwise Right Shift:"<< Rshift_result<<endl; 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++ में, 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 होगा इसलिए इसमे पहले Operand की Value का पहले प्रयोग किया जाता है उसके बाद Operand की Value में 1 जोड़ा जाता है

Example
int a = 20;
result = a++;

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

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

2) Pre Increment Operator
यदि Increment Operator को Operand के पहले लगाया जाए तो यह Pre Increment Operator कहलाता है जैसा की नाम से पता चलता है कि 

पहले Operand की Value में Increment होगा तब उस Operand का प्रयोग किया जायेगा है अर्थात Operand की Value में एक जोड़ा जाता है तब उसकी Value का Use किया जाता है

Example:
int a = 20;
result = ++a;

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

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

Program for Post and Pre Increment Operators 
#include<iostream> 
using namespace std;
int main()
 {
   int a = 10;
   int b = 10;
//Using Post-Increment operator
    int result1 = a++;
 cout<<"After Using Post-Increment Operator:"<< result1<<endl;

//Using Pre-Increment operator
    int result2= ++b;
 cout<<"After Using Pre-Increment Operator: "<<result2<<endl;
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 (- -) को Operand के बाद लगाया जाए तो Operator Post -Decrement Operator होगा इसमें Operand की Value का Use होने के बाद 1 घटाया जायेगा

Example
int a = 20;
result = a--;

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

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

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

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

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


Program for Post and Pre Decrement Operators
#include<iostream>
using namespace std;
int main()
 {
         int x = 12;
         int y = 12;
      // Using Post-Decrement operators
     int result1=x--;
 cout<<"After Using Post-Decrement Operator:"<<result1<<endl;

   // Using Pre-Decrement operators
    int result2= --y;
cout<<"After Using Pre-Decrement Operator: "<<result2<<endl;
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
C++ में 'sizeof' Operator का Use एक Variable या Data type के Size को bytes में return करने के लिए किया जाता है अर्थात एक Variable ने Memory में कितना स्थान घेरा है उसके bytes की संख्या कितनी है यह पता लगाने के लिए किया जाता है
   Example:
   int x = sizeof(int); 

ऊपर x मे 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 x = 30, y = 10, z = 7;

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

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

// Output b = 63
   
IV) Address-of Operator (&):
C++ में Address operator (&) का  Use किसी Variable के Memory address को प्राप्त करने मे होता है यह एक Unary operator है 

जब आप एक Variable में Address operator को Apply करते है तब यह उस Memory location को return करता है जिस Memory location मे Variable उपस्थित रहता है वास्ताव मे यह Memory location, Computer की Memory  का ही location है

Address operator का Use आमतौर पर Pointer, Dynamic memory allocation के साथ कार्य करते समय और Variable को reference के द्वारा function को Pass करते समय Use किया जाता है

यह Programs को विशेष Memory location के साथ Interact की अनुमति देता है जो की कुछ कार्यों जैसे Memory management और Low-level programming के लिए आवश्यक है

Example:
   int a = 5;
   int *ptr = &a; 

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

V) Pointer Operator (*):
C++ में, Pointer operator को asterisk symbol (*), के द्वारा Represent किया जाता है यह एक Variable है जो Memory Address को Store करता है

ये Operators आपको Memory Addresses और उन Addresses में Store Data को Access करने के लिए Pointer को Manipulate करने और उसके साथ कार्य करने की अनुमति देता है


 Related Posts

> C++ क्या है? उसके इतिहास, गुण, उपयोग, फायदे और नुकसान 

> Basic structure of C++ Program 

> C++ में Tokens क्या है? और उसके प्रकार

> C++ Variables क्या है?, उसके प्रकार, उसे कैसे Declare, Define करते हैं

> C++ में Constants क्या है? उसके प्रकारों की संपूर्ण जानकारी

> C++ में Basic Input और Output (cin,cout,cerr) की जानकारी

> Data type in C++ की संपूर्ण जानकारी 

> C++ में Conditional और उसके प्रकारों को जानें Practical सहित 

> C++ में Looping statements और उसके प्रकार Practical सहित 

> C++ में Jump Statements और उसके प्रकारों की संपूर्ण जानकारी Practical सहित

> C++ में Array क्या है? और उसके प्रकारों की जानकारी Practical सहित

> C++ में Function क्या है उसके प्रकार, उपयोग प्रोग्राम सहित 

> C++ में Structure क्या है Practical सहित

> OOPs Concepts in C++ in Hindi- C++ में OOPs के बारे में

> Oops के फायदे और नुकसान की जानकारी 

> OOP और POP के बीच अंतर 

> C++ में Class और Object की सम्पूर्ण जनकारी

> C++ में Array of Objects क्या है? 

> C++ में Pointers, Pointer to an objects, Pointer to an Array की संपूर्ण जानकारी हिंदी में।

C++ में Passing objects क्या है

> C++ में Reference और Type Casting की संपूर्ण जानकारी

> C++ में Access specifier की संपूर्ण जानकारी 

> C++ में Static Data Members और Member Functions के बारे में Practical सहित 

> C++ में Memory allocation और Memory management operators (new और delete) Practical सहित 

> Friend Function in C++ in Hindi 

> Friend Class in C++ in Hindi Practical सहित 

> Inline function in C++ in Hindi 

> Function Overloading in C++ in Hindi Practical सहित 

> Operator Overloading in C++ in Hindi Practical सहित 

> C++ में Constructor क्या है और उसके प्रकारों की संपूर्ण जानकारी

> C++ में Destructor क्या है ?उसकी संपूर्ण जानकारी

> C++ मे Inheritance क्या है उसके प्रकारों को जानें प्रोग्राम सहित

> C++ में Polymorphism क्या है? और उसके प्रकारों को जानें

> C++ में Virtual function की संपूर्ण जानकारी

> C++ में File handling की संपूर्ण जानकारी 

> C++ में Exception handling  की संपूर्ण जानकारी