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.

Sharing is Caring...

Other Related Posts:

  1. How some of the programming languages are named
  2. Pointers
  3. Pointers and Arrays
  4. Working with ASP

Leave a Comment

Spam protection by WP Captcha-Free

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.