By 25/02/2014 15 Comments

Increase and decrease Operators in C++

The increase operator (++) and the decrease operator (–) increase or reduce by one the value stored in a variable. They are equivalent to +=1 and to -=1, respectively.

Thus:

t++; 
t+=1;
t=t+1;

are all equivalent in its functionality: the three of them increase by one the value of t.

A characteristic of this operator is that it can be used both as a prefix and as a suffix. That means that it can be written either before the variable identifier (++a) or after it (a++). Although in simple expressions like a++ or ++a both have exactly the same meaning, in other expressions in which the result of the increase or decrease operation is evaluated as a value in an outer expression they may have an important difference in their meaning: In the case that the increase operator is used as a prefix (++a) the value is increased before the result of the expression is evaluated and therefore the increased value is considered in the outer expression; in case that it is used as a suffix (a++) the value stored in a is increased after being evaluated and therefore the value stored before the increase operation is evaluated in the outer expression.

Code Snippet # 01

Y=5;
X=++Y;
// X contains 6, Y contains 6

Code Snippet # 02

Y=5; 
X=Y++;
// X contains 5, Y contains 6






Posted in: C++ Basics

Leave your valuable Comment

Have a natural attraction for women cosmetics and replica watches uk clothes, no
more than two for men the most attractive one, is to make their own driving experience, happy and can serve as the facade of the car, another is to highlight the taste edify sentiment rolex replica watch. The replica rolex is undoubtedly the most fashionable accessories, wear a suit to attend the activities, but also get a decent match on the replica watches .