What is the importance of post increment and pre increment in C++?

164 views

What is the importance of post increment and pre increment in C++?

In: 7

7 Answers

Anonymous 0 Comments

On it’s own there is no difference.

x++;

and

++x;

Are the same.

The difference comes when you’re immediately using x.

int x = 1;
int y = x++;

has y being 1.

int x = 1;
int y = ++x;

has y being 2.

That’s what pre and post increment means.
In post increment, you do whatever, and then you increment.
In pre increment, you increment, and then you do whatever.

You are viewing 1 out of 7 answers, click here to view all answers.