C++ Assignments and Operators  Hot PDF Print E-mail
Tag it:
Delicious
Furl it!
Digg
NewsVine
Reddit
YahooMyWeb
Technorati
Articles Reviews C++
Written by Bogdan V   
Saturday, 24 February 2007

{mos_sb_discuss:31}

Assignment operator is binary operator that changes the value of its left argument. The equal ( - ), is an absolute necessity in any programming languages. This kind of operator adds the value of the righ-hand argument into the left argument. But the other assignment operators they are odd enough that they seem to be someone’s whim.



C++ creators notice that assignments often follow the form bellow:
Variable = variable # constant

Where # is some binary operator. To increment an integer operator by 2, the programmer might write something like the ex bellow

nVariable = nVariable + 2:

The expression says, “add two to the value of nVariable and store the results back intro nVariable”. Doing so changes the value of nVariable to 2 more than it was.

The same variable appears on both sides of the – sign, the Fathers of the C++ decide to create a version of the assignment operator in which a binary operator is attached. The effects says “ Thou shalt perfom whatever operation on a variable and store the results right back into the same variable”.

Every binary operator has one of these nifty assignment versions. The assignment just given could have been written this way:

nVariable = nVariable + 2;
nVariable += 2;


As you can see the first line says “ Take the value of nVariable, add 2 and store the results back into nVariable.” The line is a second form if the same expression, saying, “Add 2 to the value of nVariable.”

These assignments itself are not used all that often. However, as odd they might look, sometimes they can actually make the resulting program easier to read. 


User reviews

There are no user reviews for this item.

Add new review




Powered by jReviews

Last Updated ( Saturday, 07 July 2007 )
 
< Prev   Next >