Assignment Operators in C++ | coding for beginners | Lecture 7

 

  • Don't worry guys by the end of this lecture I'll guarantee that you will be knowing everything about assignment operators . 
  • Hey in lecture 6 we studied about the Arithmetic Operators in c++ 
  • Now we will learn about the Assignment Operators .
  • We seen some of the assignment operators in Types of Operators in C++ .
  • They are { = , +=, -=, *=, /=, %=, &=,etc., }.
  • Now I'll explain them in detail with examples . So, don't worry just relax and continue reading.

  • Assignment Operators 
  • Assignment operators are used to assign or store or give value to a variable. Confused?? ,don't worry below you can understand with example .
  • int with_dare = 25 + 2;
  • In the above statement we know that 
    • int is a keyword which decides type of values stored by variable
    • with_dare is a variable
    • 25+2 is value ie., 27.
    • Then what is  = ?,Yes I think you got it ,it is an assignment operator which stores/gives/assigns value 27 to variable with_dare
  • Ok, this looks fine and easy what about remaining??
  • { +=, -=, *=, /=, %=, &=,etc., } These looks somewhat weird right?? Don't worry again we will go with some good explanations and examples below, so continue your reading.
  • Hey , there is nothing about the above variables they can be written as bellow;
  • Eg.,1 int first = 5;
    • now first +=  8; it means first = first + 8 ;
    • In the above line both green colored statement and blue colored statement are same but form of writing is different .
    • So  ,here we assigned 5 to  a variable with name first .
    • Next we added 8 to first and assigned the final value 13 to first .
    • Hence final value of first is 13.
  • Similarly we can guess the remaining  -=, *=, /=, %=, &=,etc., Don't worry I'll elaborate some of them with examples below .
  •  Eg.,2 float second = 21.3 ;
    • second -= 2.1 ;  it means second = second - 2.1;
    • finally second = 19.2
  • Eg.,3  int anot = -2;
    • anot *= -8;  it means anot = anot * -8 ;
    • finally anot = 16.
  • I think you understood about Assignment Operators in C++ .

*****Don't worry if you are confused you will know everything in further concepts ,please read previous lectures too ,Don't give up if you are confused . Don't Panic ,be patient we will learn everything*****


Guys if you have any doubts, please let me know

Post a Comment (0)
Previous Post Next Post

How to start Coding | coding for beginners | Lecture 1