Previously we had seen the various arithmetic operators in C++. Now let us have a look at two new operators called the increment (++) and decrement (- -) operators.

Both these operators are unary operators. That means they work only on one operand.

They can be used in two ways :
1. Prefix form
2. Postfix form

Let us see each of these operators in both the forms stated above.

## 1. INCREMENT OPERATOR (++)

The increment operator increments the value of a variable. Consider the following program :

```#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int a = 5;

a++ ; //postfix form

cout <<"Value of a = "<< a << endl ;

++a; //prefix form

cout <<"Value of a = "<< a << endl ;

getch();
return 0;
}

/*
OUTPUT :
Value of a = 6
Value of a = 7
*/

```

This code first increments value of ‘a’ using ‘a++’ and prints 6.

Then it again increments value of ‘a’ using ‘++a’ and thus 7 is printed.

So here both prefix and postfix forms work the same way.

Now let us consider another program to see the difference between these two.

```#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int a = 5;

cout <<"Value of a = "<< a << endl ;

cout <<"Value of a = "<< a++ << endl ; //first print then increment

cout <<"Value of a = "<< a << endl ;

cout <<"Value of a = "<< ++a << endl ; //first increment then print

cout <<"Value of a = "<< a << endl ;

getch();
return 0;
}

/*OUTPUT :
Value of a = 5
Value of a = 5
Value of a = 6
Value of a = 7
Value of a = 7

*/

```

In the program above, when the first cout statement is executed it prints value 5 which is the original value of ‘a’.

When the next cout statement executes then also value 5 is printed and not 6. This is because a++; is in postfix form. In the postfix form, the value of the variable is first used in a statement and then it is changed. So first 5 is printed and then 5 in incremented to 6.

So when the third cout statement executes, value 6 is printed.

Now the next statement uses prefix form ++a ; In the prefix form, the value of the variable is first changed and then used in a statement. So first value of ‘a’ (which became 6 previously) is incremented to 7 and then it is printed.

Lastly, we again print value of ‘a’ which is 7.

## 2. DECREMENT OPERATOR

The decrement operator decrements the value of a variable by 1.

It is used in the same way as the increment operator in the postfix and prefix forms.

Following program shows its working.

```#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int a = 5;

cout <<"Value of a = "<< a << endl ;

cout <<"Value of a = "<< a-- << endl ; //first print then decrement

cout <<"Value of a = "<< a << endl ;

cout <<"Value of a = "<< --a << endl ; //first decrement then print

cout <<"Value of a = "<< a << endl ;

getch();
return 0;
}

/* OUTPUT
Value of a = 5
Value of a = 5
Value of a = 4
Value of a = 3
Value of a = 3

*/
```

Hope you’re clear with these two operators. Drop your queries in comments below.
{"ft_lang_label":"__label__en","ft_lang_prob":0.8149741,"math_prob":0.9932094,"size":2933,"snap":"2020-45-2020-50","text_gpt3_token_len":754,"char_repetition_ratio":0.20757937,"word_repetition_ratio":0.30494037,"special_character_ratio":0.31605864,"punctuation_ratio":0.11623932,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99965477,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-10-28T02:22:08Z\",\"WARC-Record-ID\":\"<urn:uuid:c5ae4926-c877-4b85-8695-303098cd24de>\",\"Content-Length\":\"47268\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:face6612-158c-45f7-aa4c-f95b0deab999>\",\"WARC-Concurrent-To\":\"<urn:uuid:aa5e4e67-ad13-4fd4-a5af-946b459047a0>\",\"WARC-IP-Address\":\"104.27.156.244\",\"WARC-Target-URI\":\"http://www.chewcode.com/2015/04/20/how-to-use-increment-and-decrement-operators-in-cpp/\",\"WARC-Payload-Digest\":\"sha1:4ZQZKY67IYZ6DYHNXGUYDZPHYNXT4AHF\",\"WARC-Block-Digest\":\"sha1:GUWXVSPANOM7RGJH3AU4HJCCWTJF7INW\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-45/CC-MAIN-2020-45_segments_1603107896048.53_warc_CC-MAIN-20201028014458-20201028044458-00400.warc.gz\"}"}