Assignment operators c++ In Hindi

Assignment operators c++ In Hindi

C++ प्रोग्रामिंग लैंग्वेज में असाइनमेंट ऑपरेटर का यूज़ यूजर डिफाइन डिक्लेअर किसी भी वेरिएबल पैरामीटर को मैन्युअल वैल्यू असाइन या प्रोवाइड करने में किया जाता है। असाइनमेंट ऑपरेटर C++ यूजर को मौजूदा प्रोग्राम में वेरिएबल को मल्टीप्ल टाइप से वैल्यू असाइन करने में हेल्प करते हैं. जिसमे आप एक सिंपल वेरिएबल वैल्यू असाइनमेंट से लेकर मोर काम्प्लेक्स प्रोग्रामिंग ऑपरेशन तक जो आपको एक असाइनमेंट वेरिएबल वैल्यू को अन्य अरिथमेटिक या लॉजिकल ऑपरेशन के साथ मर्ज कर यूज़ करने में हेल्प करते हैं।

Assignment operators c++ In Hindi

Popular Assignment Operators

OperatorOperator NameAssignment Operators DescriptionExample
=AssignmentIt used to Assigns the value of the right operand to the left operand and display final output.p = q
+=Add and assignHere It used to Adds the right operand value to the left operand and assigns the result to the left operand with final result.p += q
-=Subtract and assignHere It used to Subtracts the right operand value from the left operand value and assigns the result to the left operand finally.p -= q
*=Multiply and assignHere It used to Multiplies the left operand value by the right operand value and assigns the result to the finally left operand.p *= q
/=Divide and assignHere It used to Divides the left variable operand value by the right operand value and assigns the result to the finally left operand.p /= q
%=Modulus and assignHere It used to Takes the modulus of the left variable operand with the right operand value and assigns the final remainder value result to the left operand.p %= q
<<=Left shift and assignHere Left shifts operation used to the bits of the left operand by the number of positions specified by the user with right operand and assigns the result finally to the left operand.p <<= q
>>=Right shift and assignHere Right shifts operation used to the bits of the left operand by the number of positions specified by the use right operand and assigns the finally result value to the left operand.p >>= q
&=Bitwise AND and assignHere it Performs a bitwise AND operation on the left and right user define operands and assigns the final result to the left operand.p &= q
|=Bitwise OR and assignHere it Performs a bitwise OR operation on the left and right operands and assigns the final result to the left operand.p |= q
^=Bitwise XOR and assignHere it Performs a bitwise XOR operation on the left and right operands and assigns the final output result to the left operand.p ^= q
&&=Logical AND and assign (C++11)Here it Performs a logical AND operation on the left and right operands and assigns the finally result to the left operand.p &&= q

So, let’s explore all the assignment operators in the C++ programming in detail.

Simple Assignment (=) operator in C++.

किसी भी C++ प्रोगाम में = ऑपरेटर एक बेसिक असाइनमेंट ऑपरेटर का एक्साम्प्ल है। यह मौजूदा प्रोग्राम में राइट ऑपरेंड वेरिएबल की वैल्यू को लेफ्ट ऑपरेंड को वैल्यू या इनफार्मेशन असाइन करता है।

Syntax of Simple Assignment (=).

variable = value;

Example of Simple Assignment (=).

#include <iostream>

using namespace std;

int main() {

    int p = 7;  // here we Assigns 7 numeric value to variable p

    int q;

    q = p;  // here we Assigns the value of p variable (which is allready 7) to q

    cout << “original value of p = ” << p <<  ” \n simple assign value of q = ” << q << endl;  // Result – original value of p = 7 simple assign value of q = 7

    return 0;

}

Explanation of Simple Assignment (=).

  • यहाँ इस एक्साम्प्ल में, q = p,  जिसमे p वेरिएबल की वैल्यू है, जो पहले से 7 डिफाइन है. जिसे q वेरिएबल q वैल्यू को 7 वैल्यू असाइन करता है।

Add and Assign (+=) operator in C++.

किसी भी C++ प्रोगाम में += ऐड एंड असाइन ऑपरेटर राइट ऑपरेंड वेरिएबल वैल्यू को लेफ्ट पैरामीटर ऑपरेंड में ऐड करता है, और फाइनल रिजल्ट को लेफ्ट ऑपरेंड वेरिएबल वैल्यू को असाइन कर डिस्प्लै करता है।

Syntax of the Add and Assign (+=) operator.

variable += value;

Example of the Add and Assign (+=) operator.

#include <iostream>

using namespace std;

int main() {

    int p = 3;

    p += 2;  // here this expression is p = p + 2 => p = 5

    cout << “result of add and assign p value is = ” << p << endl;  // Result is  = 5

    return 0;

}

Explanation of Add and Assign (+=) operator.

  • यहाँ इस एक्साम्प्ल में  p+= 2, p = p + 2 के इक्वल वैल्यू है. इस वजह से फाइनल  ऐड एंड असाइन ऑपरेटर रिजल्ट p = 5 हो जाता है।

Subtract and assign (-=) operator in C++.

किसी भी C++ प्रोगाम में -= सब्सट्रैक्ट एंड असाइन ऑपरेटर राइट वेरिएबल ऑपरेंड वैल्यू को लेफ्ट वेरिएबल ऑपरेंड में प्रोवाइड वैल्यू से सब्ट्रैक्ट करता है, और फाइनल रिजल्ट को लेफ्ट ऑपरेंड वैल्यू को असाइन कर डिस्प्ले करता है।

Syntax of the Subtract and assign (-=) operator.

variable -= value;

Example of the Subtract and assign (-=) operator.

#include <iostream>

using namespace std;

int main() {

    int p = 7;

    p -= 3;  // here this expression is p = p – 3 => p = 4

    cout << “here Subtract and Assign p value is = ” << p << endl;  // Result p = 4

    return 0;

}

Explanation of Subtract and assign (-=) operator.

  • यहाँ इस एक्साम्प्ल में p -= 3, p = p – 3 के इक्वल वैल्यू है, इस वजह से यहाँ p का फाइनल रिजल्ट वैल्यू 4 हो जाता है।

Multiply and Assign (*=) operator in C++.

C++ प्रोगाम में *= मल्टिप्लाय एंड असाइन ऑपरेटर यूजर डिफाइन प्रोग्राम वैल्यू को लेफ्ट ऑपरेंड को राइट ऑपरेंड वैल्यू से मल्टिप्लाय करता है, और फाइनल रिजल्ट को लेफ्ट ऑपरेंड वैल्यू को असाइन कर डिस्प्ले करता है।

Syntax of the Multiply and Assign (*=) operator.

variable *= value;

Example of the Multiply and Assign (*=) operator.

#include <iostream>

using namespace std;

int main() {

    int p = 7;

    p *= 3;  // here this expression is p = p * 3 => p = 21

    cout << “Multiply and Assign value of p = ” << p << endl;  // Result p = 21

    return 0;

}

Explanation of Multiply and Assign (*=) operator.

  • यहाँ इस एक्साम्प्ल में p *= 3, p = p * 3 एक्सप्रेशन के इक्वल वैल्यू है. इस वजह से यहाँ p की फाइनल रिजल्ट वैल्यू 21 हो जाती है।

Divide and Assign (/=) operator in C++.

C++ प्रोगाम में /= डिवाइड एंड असाइन ऑपरेटर यूजर डिफाइन वेरिएबल लेफ्ट ऑपरेंड वैल्यू को राइट ऑपरेंड से डिवाइड करता है, और फाइनल रिजल्ट आउटपुट को लेफ्ट ऑपरेंड वैल्यू को असाइन कर डिस्प्ले करता है।

Syntax of the Divide and Assign (/=) operator.

variable /= value;

Example of the Divide and Assign (/=) operator.

#include <iostream>

using namespace std;

int main() {

    int p = 20;

    p /= 4;  // p = p / 4 => p = 5

    cout << “Divide and Assign value of p = ” << p << endl;  // Result p = 5

    return 0;

}

Explanation of Divide and Assign (/=) operator.

  • यहाँ इस एक्साम्प्ल में p /= 4, p = p / 4 के इक्वल वैल्यू है, इस वजह से यहाँ p का फाइनल रिजल्ट 5 हो जाता है।

Modulus and Assign (%=) operator in C++.

C++ प्रोगाम में %= मॉडुलुस एंड असाइन ऑपरेटर, राइट वेरिएबल ऑपरेंड द्वारा लेफ्ट ऑपरेंड वैल्यू का मॉड्यूलस फाइंड करता है, और फाइनल मॉडुलुस रिजल्ट को लेफ्ट ऑपरेंड वैल्यू को असाइन कर डिस्प्ले करता है। यह मॉड्यूलस ऑपरेटर में डिवीज़न का बचा हुआ हिस्सा रिमाइंडर वैल्यू को डिस्प्ले करता है।

Syntax of the Modulus and Assign (%=) operator.

variable %= value;

Example of the Modulus and Assign (%=) operator.

#include <iostream>

using namespace std;

int main() {

    int p = 7;

    p %= 3;  // p = p % 3 => p = 1 (here remainder value of 7 / 3)

    cout << “Divide and Assign value of p = ” << p << endl;  // Result p = 1

    return 0;

}

Explanation of the Modulus and Assign (%=) operator.

  • यहाँ इस एक्साम्प्ल में  p %= 3, p = p % 3 के इक्वल वैल्यू है, और यहाँ रिजल्ट 7 % 3 का बचा हुआ हिस्सा रिमाइंडर वैल्यू है, जो की फाइनल आउटपुट 1 के रूप में है।

Shift and Assign (<<= and >>=) operator in C++.

C++ प्रोगाम में <<= और >>= लेफ्ट और राइट शिफ्ट एंड असाइन ऑपरेटर का यूज़ एक के बाद एक बिटवाइज़ लेफ्ट और राइट शिफ्ट बिट वैल्यू को उसकी मौजूदा बिट मेमोरी लोकेशन से शिफ्ट या मूव करने में किया जाता है। शिफ्ट एंड असाइन ऑपरेटर लेफ्ट ऑपरेंड के बिट्स को राइट ऑपरेंड द्वारा इंडीकेट की गई स्पेसिफिक न्यूमेरिक बिट शिफ्टिंग पोजीशन को शिफ्ट करते हैं, और फाइनल रिज़ल्ट आउटपुट को लेफ्ट ऑपरेंड वैल्यू को असाइन कर डिस्प्ले करते हैं।

Syntax of the Shift and Assign (<<= and >>=) operator.

variable <<= value; // लेफ्ट शिफ्ट और असाइन एक्सप्रेशन

variable >>= value; // राइट शिफ्ट और असाइन एक्सप्रेशन

Example of the Shift and Assign (<<= and >>=) operator (left shift).

#include <iostream>

using namespace std;

int main() {

    int p = 7;  // here equivalent binary value – 0111

    p <<= 3;     // p = p << 3 => binary value – 00111000, which is 56 in decimal

    cout << “Left shift and assign p value = ” << p << endl;  // Result p = 56

    return 0;

}

Explanation of the Left Shift and Assign (<<= and >>=) operator.

  • यहाँ इस एक्साम्प्ल में p <<= 3, p के बिट्स को 3 पोजीशन लेफ्ट साइड की ओर शिफ्ट करता है। और इसका फाइनल रिजल्ट 56 होता है।

Example of the Shift and Assign (<<= and >>=) operator (right shift).

#include <iostream>

using namespace std;

int main() {

    int p = 29;  // here equivalent binary value – 0001 1101

    p >>= 3;     // p = p >> 3 => binary value – 0011, which is 3 in decimal

    cout << “Right shift and assign p value = ” << p << endl;  // Result p = 3

    return 0;

}

Explanation of the Right Shift and Assign (<<= and >>=) operator.

  • यहाँ इस एक्साम्प्ल में p >>= 3, p वैल्यू के बिट्स को 3 पोजीशन राइट डायरेक्शन की ओर शिफ्ट करता है, और फाइनल रिजल्ट 3 होता है।

Bitwise AND, OR, and XOR assignment (&=, |=, ^=) operators in C++.

C++ प्रोगाम में बिटवाइज एंड, और, एंड एक्सऔर ऑपरेटर यूजर डिफाइन वेरिएबल राइट ऑपरेंड के साथ लेफ्ट ऑपरेंड वैल्यू पर बिटवाइज़ AND, बिटवाइज़ OR, और बिटवाइज़ XOR ऑपरेशन अप्लाई करने में हेल्प करते हैं, और फाइनल रिजल्ट को नतीजा लेफ्ट ऑपरेंड को असाइन कर डिस्प्ले करते हैं।

Syntax of the bitwise AND, OR, and XOR assignment (&=, |=, ^=) operators.

variable &= value; // बिटवाइज़ AND और असाइन एक्सप्रेशन

variable |= value; // बिटवाइज़ OR और असाइन एक्सप्रेशन

variable ^= value; // बिटवाइज़ XOR और असाइन एक्सप्रेशन

Example of the (bitwise AND) operator.

#include <iostream>

using namespace std;

int main() {

    int p = 9;  // here equivalent binary value – 00001001

    int q = 3;  // here equivalent binary value – 00000011

    p &= q;      // p = p & q => binary: 00001001 & 00000011 = which is 1 in decimal

    cout << “Bitwise AND and assign p value = ” << p << endl;  // Result p = 1

    return 0;

}

Explanation of the (bitwise AND) operator.

यहाँ इस एक्साम्प्ल में p &= q, p और q पर एक बिटवाइज़ AND ऑपरेशन को अप्लाई करता है, और फाइनल एंड बिटवाइज ऑपरेटर रिजल्ट 1 (00000001) है।

Example of the (bitwise OR) operator.

#include <iostream>

using namespace std;

int main() {

    int p = 8;  // here equivalent binary value – 00001000

    int q = 2;  // here equivalent binary value – 00000010

    p |= q;      // p = p | q => binary: 00001010, which is 10 in decimal

    cout << “Bitwise OR and assign p value = ” << p << endl;  // Result p = 10

    return 0;

}

Explanation of the (bitwise OR) operator.

  • यहाँ इस एक्साम्प्ल में p |= q, p और q पर एक बिटवाइज़ OR ऑपरेशन को अप्लाई करता है, और फाइनल और बिटवाइज ऑपरेटर रिजल्ट 10 (00001010) है।

Example of the (bitwise XOR) operator.

#include <iostream>

using namespace std;

int main() {

    int p = 7;  // here equivalent binary value – 00000111

    int q = 4;  // here equivalent binary value – 00000100

    p ^= q;      // p = p ^ q => binary: 00000011, which is 3 in decimal

    cout << “Bitwise XOR and assign p value = ” << p << endl;  // Result p = 3

    return 0;

}

Explanation of the (bitwise XOR) operator.

  • यहाँ इस एक्साम्प्ल में p ^= q, p और q पर एक बिटवाइज़ XOR ऑपरेशन को अप्लाई करता है, और और फाइनल एक्सऔर बिटवाइज ऑपरेटर रिजल्ट 3 (00000011) है।

Summary of Assignment Operators

OperatorAssignment Operators DescriptionExample
=Basic assignment operator used to assign basic valuep = q
+=Add and assign used to add value and assign the final resultp += q
-=Subtract and assign used to subtract value and assign the final resultp -= q
*=Multiply and assign used to multiply value and assign the final resultp *= q
/=Divide and assign used to divide value and assign the final resultp /= q
%=Modulus and assign used to add divide value and assign the final remainder value to the resultp %= q
<<=Left shift and assign used to add specified left bit shifting by userp <<= q
>>=Right shift and assign used to add specified right bit shifting by userp >>= q
&=Bitwise AND and assign used to perform bitwise AND operation on data type valuep &= q
=`Bitwise OR and assign used to perform bitwise OR operation on data type valuep |= q
^=Bitwise XOR and assign used to perform bitwise XOR operation on data type valuep ^= q

Leave a Reply