Saturday 8 October 2022

Assignment Operators in Programming Language |Assignment Operators in c++, C Language |What is Assignment Operator in C language, C++ |What is Assignment operator in Computer Language |Types of Operators in Programming Language |What is Operator in C language, C++

 - : Assignment Operators :-

    Operators are those symbols which are used between operands to perform Mathematical and Logical operations.

    Assignment Operators are used to assign the values to the variable. Assignment Operator Includes Following Symbols giver below -

  • (+=)
  • (-=) 
  • (*=)
  • ( /=)
  • (%=)
  • (=) 
Keypoint 1:- 
        Data type of variable should be same as the value to be assigned.
For Example, 
             X += 10;
here X containing an integer type data, so it is mandatory to specify the Data type of the variable. so now it will be written as - 
      int X += 10;
 
Keypoint 2:- 
          In the assignment operator, variable performs operation on current value and then the result assigned to that variable which becomes original value of the variable. 
For Example, 
        suppose X = 10;
              now we want to perform X += 5 using (+=) operator. 
So here meaning of X+=5 is that 
                  X = X+5;
                 X = 10 + 5;            //we took X = 10 for example 
                 X = 15;                 //now further operation we be performed by                                                      assuming the value of X as 15. 

_____________________________________________________________
A program to understand Assignment Operators 

#include<iostream>
using namespace std ;
int main(){
       int X = 10;
       cout<<"now value of X after performing (X+=5) Will be = " <<X+=5 <<endl ;                    //X = X+5,
       cout<<"now value of X after performing (X-=3) Will be = " <<X-=3  <<endl ;                    //X = X-3,
       cout<<"now value of X after performing (X*=4) Will be = " <<X*=4 <<endl ;                   //X = X*4,

       cout<<"now value of X after performing (X/=2) Will be = " <<X/=2 <<endl ;                    //X = X/2,
       cout<<"now value of X after performing (X%=8) Will be = " <<X%=8 <<endl ;                   //X = X%8,

      return 0 ;
_____________________________________________________________
Output :-
now value of X after performing (X+=5) Will be = 15
now value of X after performing (X-=3) Will be = 12
now value of X after performing (X*=4) Will be = 48
now value of X after performing (X/=2) Will be = 24
now value of X after performing (X%=8) Will be = 0

_____________________________________________________________

























No comments:

Post a Comment