What is Operators & its Types and Expression
What is Operators –
Operators वे Symbol हैं जो Computer को कुछ Mathematical या Logical execute करने के लिए कहते हैं। एक Mathematical या Logical expression सामान्यतः एक Operator की सहायता से बनता है। C programming कई Operators Offers करता है जिन्हें 8 Categories में Classified किया है।
1. Arithmetic operators
2. Relational operators
3. Logical operators
4. Assignment operators
5. Increment and Decrement operators
6. Conditional operators
7. Bitwise operators
-
Arithmetic Operators :
एक Arithmetic Operator एक Mathematical Function है जो दो Operands लेता है और उन पर Calculation करता है। उनका उपयोग Common Arithmetic में किया जाता है और अधिकांश Computer Language में ऐसे Operators का एक समूह होता है जिनका उपयोग कई प्रकार की sequential calculation करने के लिए Equation के भीतर किया जा सकता है। Basic Arithmetic Operators हैं:
- Addition (+)
- Subtraction (-)
- Multiplication (×)
- Division (÷)
2. Relational Operators
Relational Operators दो Operands के बीच Relation की जाँच करता है। यदि Relation True है, तो यह 1 Return करता है; यदि Relational False है, तो यह 0 Value देता है।Relational Operators का उपयोग Decision making और Loop में किया जाता है।
Operator | Meaning Of Operator | Example |
== | Equal to | 5==3 is evaluated to 0 |
> | Greater than | 5>3 is evaluated to 1 |
< | Less than | 5<3 is evaluated to 0 |
!= | Is not equal to | 5!=3 is evaluated to 1 |
>= | Greater than or equal to | 5>=3 is evaluated to 1 |
<= | Less than or equal to | 5<=3 is evaluated to 0 |
3. Logical operator
Logical Operator एक Symbol या Word है जिसका उपयोग दो या दो से अधिक expressions को Connect करने के लिए किया जाता है, सामान्य Logically Operators में AND, OR, और NOT शामिल हैं।
Operators | Example/Description |
&& (logical AND) | x>5)&&(y<5) जब दोनों Conditions, True होती हैं तो यह True हो जाती है |
|| (logical OR) | (x>=10)||(y>=10) कम से कम एक Condition के True होने पर यह True हो जाता है |
! (logical NOT) | !((x>5)&&(y<5)) यह Operand की State को Reverse कर देता है “((x>5) && (y<5))” यदि “((x>5) && (y<5))” True है, Logical Not Operator(!) इसे False बनाता है |
4. Bitwise Operator
C में, निम्नलिखित 6 Operator Bitwise Operator हैं जो Bit-Level पर Work करते हैं
a. Bitwise AND(&)- दो Numbers को Operands के रूप में लेता है और करता है और दो Numbers के प्रत्येक Bit पर। AND का Result केवल 1 होता है यदि दोनों Bit 1 हैं।
b. Bitwise OR(|) two numbers operands के Form में लेता है। और OR Operator every bit के two numbers पर work करता है। इसका result 1 तब होता है अगर दोनों में से कोई Bits एक (1 )है।
c. Bitwise XOR(^) C में Operands के रूप में दो Numbers लेता है और हर दो Numbers पर XOR करता है। यदि दो Bit Different हैं तो XOR का Result 1 है।
d. left shift(>>) C में two numbers लेता है , first operand के bits को right shifts करता है , the second operand decides करता है कि कितने number of places पर shift करना है।
e. bitwise NOT(~) C में one number लेता है ,और इसके सभी Bits को inverts करता है।
5. Assignment operators :
Assignment Operators का उपयोग एक Variable को Value Provide करने के लिए किया जाता है। Assignment Operator का Left Side Operands एक Variable होता है जिसमे Assignment Operator का उपयोग करके Right Side Operands से Value Assign करते है।Right side का मान Left Side के Variable के Same Data Type का होना चाहिए अन्यथा Compiler एक Error Raise करेगा।
विभिन्न प्रकार के Assignment Operator नीचे दिखाए गए हैं:
“=”: यह सबसे Easiest Assignment Operator है। इस Operator का Use Left Side के Variable के Right Side को Value Assign करने के लिए किया जाता है।
उदाहरण के लिए:
a = 10;
b = 20;
ch = ‘y’;
“+=”: यह Operator ‘+’ और ‘=’ Operators का Combination है। यह Operator पहले Left Side के Variable के Present Value को Right side के Value में जोड़ता है और फिर Result को Left Side के Variable को Assign करता है।
उदाहरण के लिए:
(a += b) can be written as (a = a + b)
If initially value stored in a is 5. Then (a += 6) = 11.
“-=” : यह Operator ‘-‘ और ‘=’ Operators का Combination है। यह Operator पहले Right Side के Value से Left Side के Variable के Current Value को Substract करता है और फिर Left side के Variable को Result Assign करता है।
उदाहरण के लिए:
(a -= b) can be written as (a = a – b)
If initially value stored in a is 8. Then (a -= 6) = 2.
“*=” : यह Operator ‘*’ और ‘=’ Operators का Combination है। यह Operator पहले Left Side के Variable के Current Value को Right Side के Value से Multiply करता है और फिर Result को Left Side के Variable को Assign करता है।
उदाहरण के लिए:
(a *= b) can be written as (a = a * b)
If initially value stored in a is 5. Then (a *= 6) = 30.
“/ =” : यह Operator ‘/’ और ‘=’ Operators का Combination है। यह Operator पहले Left Side के Variable के Current Value को Right Side के Value से Devide करता है और फिर Result को Left Side के Value को Assign करता है।
उदाहरण के लिए:
(a /= b) can be written as (a = a / b)
If initially value stored in a is 6. Then (a /= 2) = 3.
6. Increment operators :
Increment Operator का उपयोग किसी Expression में किसी वेVariable के मान को Increment करने के लिए किया जाता है। Pre-Increment में, Value को पहले Increment किया जाता है और फिर Expression के अंदर Used किया जाता है।
Post Increment में पहले Expression के अंदर Value का Used किया जाता है और फिर Increment किया जाता है।
7. Decrement Operators:
Decrement Operator का Used किसी Expression में एक Variable के Value को Substract किया किया जाता है। Pre-Decrement में, Values को पहले Decrement किया जाता है और फिर Expression के अंदर Used किया जाता है। जबकि Post-Decrement में पहले Expression के अंदर Values Used किया जाता है और फिर Decrement किया जाता है।
8. Conditional Operator:
Conditional Operator if-else Statement के समान है क्योंकि यह if-else Statement के समान Algorithm का पालन करता है लेकिन Conditional Operator कम Space लेता है और कम से कम Shortest Way से if-else Statement लिखने में मदद करता है।
Since Conditional ‘?:’ काम करने के लिए 3 Operands लेता है, इसलिए उन्हें Ternary Operator भी कहा जाता है।
Working:
यहां, Expression 1 Evaluated की जाने वालीCondition है। यदि Condition (Expression 1) सही है तो Expression 2 Execute किया जाएगा और Result वापस कर दिया जाएगा। Otherwise, यदि Condition (Expression) गलत है, तो Expression 3 Execute की जाएगी और Result returned कर दिया जाएगा।