Thursday, December 5, 2019

Operators in C++

Introduction to C++ Operators

किसी भी C++ program में data पर operations perform किये जाते है। इसके लिए सबसे पूर्व data को variables के द्वारा computer memory में store किया जाता है। इसके बाद C++ द्वारा supported operators को use करते हुए उस data पर operations perform किये जाते है।

उदाहरण के लिए आप दो variables जिनमे integer values store की गयी है उनके बीच addition operation perform करते है। ऐसा आप addition operator (+) द्वारा करेंगे।
C++ आपको अलग अलग operations perform करने के लिए अलग अलग type के operators provide करती है। जिन्हें आप variables के साथ प्रयोग करते है।
उदहारण के लिए यदि आप program में arithmetic operations जैसे की addition, subtraction, division आदि perform करना चाहते है तो इसके लिए arithmetic operators +, -, / आदि का प्रयोग करते है।
उसी प्रकार यदि आप program में logic (data को compare करना) perform करना चाहते है तो उसके लिए relational operators जैसे की <, >, = आदि use करते है।
Operators के साथ define किये जाने वाले variables operands कहलाते है। उदाहरण के लिए आपने 2 variables a और b create किये है। अब आप इन दोनों के बीच addition operation perform करके result c variable में store करना चाहते है। आप इस प्रकार code लिखते है।
                           c = a + b;
C++ में दो तरह के operators पाए जाते है। इनके बारे में निचे बताया जा रहा है।

Binary – ऐसे operators जो दो operands के साथ operation perform करते है binary operators कहलाते है। उदाहरण के लिए सभी arithmetic operators binary operators होते है। 
Unary – ऐसे operators जो एक operand के साथ operation perform करते है unary operator कहलाते है। उदाहरण के लिए increment (++) और decrement (–) operators unary operators होते है। इन्हे एक ही variable (operand) के साथ use किया जाता है। 
C++ में available विभिन्न operators के बारे में आगे detail से बताया जा रहा है।
Arithmetic Operators 
Arithmetic operators वे operators होते है जिनके द्वारा arithmetic operations perform किये जाते है। C++ द्वारा supported arithmetic operators की list निचे दी जा रही है।
Operator
Explanation 
Syntax
+ (Addition)
Adds a and b
a + b
– (Subtraction)
Subtract b from a
a – b
* (Multiplication)
Multiply a and b
a * b
/ (Division)
Divide a by b
a / b
% (Modulus)
Divide a by b and return remaining value 
a % b

Relational Operators
Relational operators data को compare करने या data के बीच relation define करने के लिए प्रयोग किये जाते है। ये operators true और false के रूप में boolean value return करते है। C++ में available relational operators की list निचे दी जा रही है।

Operator
Explanation 
Syntax
> (Greater than)
Checks whether a is greater than b
a > b
< (Lesser than)
Checks whether a is lesser than b

a < b
>= (Greater than & equal)
Checks whether a is greater than & equal to b 
a >= b
<= (Lesser than & equal)
Checks whether a is lesser than & equal to
a <= b
== (Equal)
Checks whether a is equal to b 
a == b
!= (Not equal)
Checks whether a is not equal to b
a != b
Logical Operators
Logical operators program में logic perform करने के लिए प्रयोग किये जाते है। ये operators conditional expressions के बीच प्रयोग किये जाते है और boolean value true या false return करते है। C++ में available logical operators के बारे में निचे दिया जा रहा है।  

Operator
Explanation 
Syntax
&& (AND)
returns true if both conditions are true
cond1 && cond2
|| (OR)
returns true if any of the two condition is true
cond1 || cond2
! (NOT)
returns true if condition is not true, Unary operator 
!cond
Bitwise Operators
Bitwise operators program में bit operations perform करने के लिए प्रयोग किये जाते है। सबसे पहले variables की values को bits में convert किया जाता है और उसके बाद उन पर operations perform किये जाते है। ये operators true और false return करते है। C++ में available bitwise operators की list निचे दी जा रही है।

Operator
Explanation 
Syntax
& (Binary AND)
Returns bits which are identical in a and b
a & b
| (Binary OR)
Returns all bits from a and b

a | b
^ (XOR)
Returns bits which are in a but not in b
a ^ b
~ (Binary Ones compiment)
Unary operator, Change 0 bits to one and 1 bit to 0
~a
<< (Left Shift)
Shifts bits of a to left by number given on right side of <<
a << number
>> (Right Shift)
Shifts bits of a to right by number given on right side of >>
a >> number
Assignment Operators
Program में assignment operations perform करने के लिए assignment operators प्रयोग किये जाते है। C++ में available assignment operators के बारे में निचे दिया जा रहा है।

Operator
Explanation 
Syntax
= (Assignment)
Assign value of a to b
a = b
+= (Plus and assignment)
Add value of a & b then assign result to a

a += b
-= (Minus and assignment)
Subtract value of b from a then assign result to a
a -= b
*= (Multiply and assignment)
Multiply a & b then assign result to a
a *= b
/= (Divide and assignement)
Divide a by b then assign result to a
a /= b
%= (Modulus and assignment)
Divide a by b then assign remaining value to a
a %= b
Conditional Operator (?:)
C++ आपको conditional operator provide करती है। यह operator ? और : के combination से बनता है। यह operator if else statement का short रूप होता है। इस operator का general syntax निचे दिया जा रहा है।

                           condition ? true-part : false-part

जैसा की आप ऊपर दिए गए syntax में देख सकते है सबसे पूर्व condition define की जाती है। इसके बाद question mark (?) symbol लगाया जाता है।
इस symbol के बाद वह statement लिखा जाता है जो condition true होने पर use किया जाएगा। इसके बाद colon (:) symbol लगाया जाता है। Colon symbol के बाद वह code लिखा जाता है जो condition के true होने पर use किया जाएगा।
इस operator को मुख्यतः condition के आधार पर variables को value assign करने के लिए प्रयोग किया जाता है।
sizeof() Operator 
C++ में sizeof operator किसी भी variable की size return करता है। इसका syntax निचे दिया जा रहा है।

                       sizeof(variable-name);

जिस variable की size आप पता करना चाहते है उसका नाम brackets में लिखा जाता है।
* (Pointer) Operator 
Pointer variable define करने के लिए pointer operator का प्रयोग किया जाता है। इस operator का general syntax निचे दिया जा रहा है।

                        data-type *variable-name;

Pointer variable का प्रयोग किसी दूसरे operator का address store करने के लिए किया जाता है।

& (address of) Operator 
C++ में address of operator किसी भी variable का address return करता है। इस operator का syntax निचे दिया जा रहा है।

                        pointer-variable = &variable-name;

Address of operator को उस variable के नाम से पूर्व define किया जाता है जिसका variable आप access करना चाहते है। Address को किसी pointer variable में store किया जाता है।






No comments:

Post a Comment

how to add watermark in movavi video editor | movavi watermark | how to ...

What is static keywords in java ? static keywords in java is a main topic of java.