PropellerAds
Posted by : Unknown Sunday 12 October 2014

Most of the new programmers are stuck between post and pre increment.
What is the difference between ++a and a++. This post will clear your confusion.
++a is a pre increment type in which first of all 1 is added in a and then its value is considered in expression. where ever in pre increment type that is a++ first of all a value is considered for expression than 1 is added to a.

Did'nt Understand?? this example will make the idea clear.

if a = 3;
b = ++a; (In this case there is pre-increment a will increase and then its value is returned to b so b will                  be 4 and a will also become 4)

if a = 3;
b = --a; (In this case there is pre-decrement a will first decrease and then its value is returned to b.                      so b will be equal to 2 and a also will be 2)

if a = 3;
b = a++ (In this case there is post-increment  a value will be returned to b and then a will increase by                  1 that is b will be 3 and a will become 4)

if a = 3;
b = a--  (In this case there is post-decrement  a value will be returned to b and then a will decrease by               1 that is b will be 3 and a will become 2)

Leave a Reply

Subscribe to Posts | Subscribe to Comments

PropellerAds
PropellerAds

Popular Post

Powered by Blogger.

- Copyright © BSCS -Metrominimalist- Powered by Blogger - Designed by Johanes Djogan -