Increment and Decrement Operators

by Shabbir on April 27, 2008

in C/C++

Very common programming practice is adding or subtracting an integer variable by 1.

We know that adding 1 to variable is incrementing, and subtract 1 from variable is decrementing. It only works with integer values.

Let us see some examples

i++;
i=i+1;
i+=1;

This three commands are all the same. It increments the variable i by 1. Its the same for decrementing.

The incrementation and decrementation can be made with prefix of postfix

i++;    //postfix
++i;    //prefix

Here are some examples of using prefix and postfix

int j=++i;        //1
int j=i--;        //2

The above commands are equal to this

i++;             //1
int j=i;
 
int j=i;         //2
i--;

or

i=i+1;             //1
int j=i;
 
int j=i;           //2
i=i-1;

This operators are used in many programming languages, and are very simple for using.
As we know C++ is one lever above C, so, maybe the postfix was the inspiration for Bjarne Stroustrup to name the new programming language to C++ in 1979.

Share:
  • Digg
  • Facebook
  • StumbleUpon
  • Technorati
  • Twitter
Other Related Posts:
  1. How some of the programming languages are named
  2. Pointers
  3. Pointers and Arrays
  4. Read From File In C++

Want More Tips on How to Make Money Online?
Enter your Name and Email below to subscribe and start 1 month free course now.

Name:
Email:
You would require to confirm your email address before we send you any updates. We respect your privacy as much as you do.
Powered by Aweber
blog comments powered by Disqus

Previous post:

Next post:

    About the Author

  • author photo

    My Name is Shabbir Bhimani and I am developer by profession in the field of applications, web and database. Currently doing full time online marketing and like to share my experiences on how you can make money online @ CodeItWell.com. Read more ...


    See how you can get in touch with me.