Artikel Terbaru

Operators

Introduction to C Operators


Introduction to C Operators
Variables के अंदर values store करवाकर आप उन variables पर कई प्रकार के operations perform कर सकते है। उदहारण के लिए दो integer variables के अंदर value store करवाकर आप addition का operation perform कर सकते है और उन दोनों variables की values के sum को print करवा सकते है।



इसी प्रकार आप और भी अलग अलग operations variables के साथ perform कर सकते है। Variables के साथ operations perform करने के लिए आपको अलग अलग operators यूज़ करने पड़ते है। इस chapter में आपको ऐसे ही operators के बारे में बताया जा रहा है।


Operations में operators के साथ जो variables यूज़ होते है वो operand कहलाते है।


c = a + b;


उपर दिए गए statement में a और b को operator (+) के साथ यूज़ किया गया है इसलिए ये दोनों variables operands कहलायेंगे।



Operators 2 प्रकार के होते है।

  • Unary -  इस प्रकार के operators सिर्फ एक ही operand के साथ यूज़ किये जाते है।  
  • Binary - इस प्रकार के operators के साथ 2 operands यूज़ किये जाते है।  

Arithmetic Operators
Arithmetic operators mathematical operations perform करने के लिए यूज़ किये जाते है। जैसे की addition, subtraction, division और multiplication आदि। Arithmetic operators 5 प्रकार के होते है। ये basic mathematical operators होते है।



 Operators 
Description 
+ (Addition)
दो variables की values को add करता है।  
- (Subtraction) 
एक variable की value में से दूसरे variable की value subtract करता है। 
* (Multiplication) 
2 variables की values को multiply करता है।  
/ (Division) 
एक variable की value से दूसरे variable की value को divide करता है। 
% (Modulus) 
Division के बाद शेष बची हुई value को प्राप्त करने के लिए यूज़ किया जाता है। 

Relational Operators 

Relational operators दो variables की values को compare करने के लिए यूज़ किये जाते है। जैसे की आप इन operators का यूज़ करके पता लगा सकते है की क्या किन्ही दो variables की values बराबर है और यदि बराबर नहीं है तो कौनसे variable की value बड़ी है और कौनसे variable की value छोटी है। 

इस तरह के operators को decision making statements (if,if-else,switch,for,while आदि) के साथ यूज़ किया जाता है। ये operators condition check करने के लिए यूज़ किये जाते है। Condition true होने पर value true हो जाती है और condition false होने पर value false हो जाती है।

Operators  
Description
== (Equal To)
Check करता है की क्या दोनों variables की values equal है।  
!= (Not Equal To)
Check करता है की क्या दोनों variables की values non equal है।  
<  (Lesser Than)
Check करता है की क्या left operand की value right operand से छोटी है।  
> (Greater Than) 
Check करता है की क्या left operand की value right operand से बड़ी है।   
<=  (Lesser than equal)
Check करता है की क्या left operand की value right operand से छोटी या उसके समान है।  
>=  (Greater than equal)
Check करता है की क्या left operand की value right operand से बड़ी या उसके समान है।  

Logical Operators 

Logical operators को decision making statements के साथ यूज़ किया जाता है। ये operators control statements में एक साथ दो condition को check करने के लिए यूज़ किये जाते है। उदाहरण के लिए आप किसी if statement में एक की जगह 2 conditions check कर सकते है।



Operators  
Description 
&&(AND) 
जब दोनों conditions true होती है तब control statement की value true हो जाती है।   
|| (OR) 
जब कोई भी एक condition true हो तो भी control statement की value true हो जाती है।   
! (NOT) 
एक ही condition के साथ यूज़ किया जाता है। जब वो condition false होती है तो control statement की value true हो जाती है।    


BitWise Operators 

Bitwise operators दिए गए variables पर bit level operations perform करने के लिए यूज़ किये जाते है। Variables की decimal values bits में convert की जाती है। इसके बाद उन bits पर operations perform किये जाते है।



Operators  
Description 
& (Bitwise AND) 
इस operator के द्वारा दोनों variables की same position वाली bits के साथ AND operation perform किया जाता है।   
| (Bitwise OR) 
इस operator के द्वारा दोनों variables की same position वाली bits के साथ OR operation perform किया जाता है।   
~ (Bitwise NOT) 
सिर्फ एक ही operand के साथ यूज़ किया जाता है। जिस variable के साथ इसे यूज़ किया जाता है उस variable की value की सभी bits opposite हो जाती है। जैसे की 0 है तो 1 हो जाती है और 1 है तो zero हो जाती है।     
^ (XOR) 
ये एक special type का OR operator होता है।  opposite bits होने पर 1 return करता है और same bits होने पर 0 return करता है।   
<< (Left Shift) 
Left side के variable की bits को right side के variable में दी गयी value जितना left में shift करता है।   
>> (Right Shift) 
Left side के variables की bits को right side क&#23#2375; variable में दी गयी value जितना right में shift करता है।   
     

जैसा की आपको पता है bitwise operators bits के साथ work करते है। मान लीजिये आपने program में 2 variables a और b create किये हुए है। इन दोनों variables में आपने क्रमशः 3 और 5 values store करवाई हुई है। इनकी bits पर work करने के लिए सबसे पहले आप इन्हें binary में convert कर सकते है।



3  = 00000011

5  = 00000101



सिर्फ आपको समझाने के purpose से इन्हें binary में convert किया गया है। आपको program में binary values insert करवाने की आवश्यकता नहीं है। Computer information को binary form में ही store करता है। ऊपर define किये गए सभी operations इन bits पर ही perform किये जायेंगे।

Assignment Operators
Assignment operators variables की values को एक दूसरे को assign करने के लिए यूज़ किये जाते है।



Operators 
Description 
=  
Right side के operand की value को left side के operand को assign करता है।   
+= 
Left side के operand में right side के operand की value को add करके result left side वाले operand को assign करता है। इसे आप इस प्रकार भी लिख सकते है। a = a+b;   
-= 
Left side के operand की value में से right side के operand की value को subtract करके result left side के variable में store करवाता है। इसे आप इस प्रकार भी लिख सकते है। a=a-b;   
*= 
Left side के operand की value को right side के operand की value से multiply करके result को left side के operand में store करता है।   
/= 
Left operand की value को right operand की value से divide करके result को left side के operand में store करता है।   
%= 
Left side के operand की value को right side के operand की value से divide करके शेष बचे हुए result को left side के operand में store करता है।   

Increment/Decrements operators 

किसी भी variable की value को एक number से instantly increase या decrease करने के लिए आप increment/ decrements operators यूज़ कर सकते है।
   
 Operators 
Description  
 ++ (increment) 
ये एक unary operator होता है। ये operand की value को एक number से increase करता है। जब यह operand के पहले लगता है तो value पहले increment होती है और बाद में यूज़ की जाती है। जब ये operator operand के बाद लगता है तो operand की value यूज़ होने के बाद increment होती है।  
 --(decrements) 
ये भी एक unary operator होता है। ये operand की value को एक number से decrease करता है। जब इसे operand से पहले यूज़ किया जाता है तो value यूज़ होने से पहले decrease होती है। जब इसे variable के बाद यूज़ किया जाता है तो value पहले यूज़ होती है और बाद में decrease होती है।  

Conditional (?:) Operator

Conditional operator को ternary operator भी कहा जाता है। ये if-else statement की short form होती है। इसका general structure इस प्रकार होता है।



contion ? stmnt1 : stmnt 2;
   
यदि condition true हो तो statement one return होगा नही तो statement 2 return होगा।



5>3 ? true : false;

Special C Operators

Operators  
Description 
sizeof (var_name )
Memory में variables की size return करता है।   
Variables का memory address return करता है।   
Variable का pointer return करता है।   

Post a Comment

0 Comments