Home Pre and post increment
Post
Cancel

Pre and post increment

Both the pre(++a) and post increment(a++) in C++ means a=a+1; basically increasing the value of the variable by one but the difference between them is that in pre increment first value of a is increased by one then the line is executed whereas in post increment first the line is executed then the value of a is increased by one.Same can be said for pre(--a) and post decrement(a--).

1
2
3
4
5
6
7
8
9
10
11
12
13
#include<iostream>
using namespace std;
int main()
{
    int a=8,b=8,x,y;
    x=++a;
    y=b++;
    cout<<x<<' '<<a<<'\n';
    cout<<y<<' '<<b;
    return 0;
}

OUTPUT:

output

This post is licensed under CC BY 4.0 by the author.

Trending Tags