C++ Assignments and Operators
|
|
|
|
| Articles Reviews C++ | |
| Written by Bogdan V | |
| Saturday, 24 February 2007 | |
|
{mos_sb_discuss:31}
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. Powered by jReviews |
|
| Last Updated ( Saturday, 07 July 2007 ) | |
| < Prev | Next > |
|---|







