# What is difference between ++i, i++ in C/C++?

+1 vote
98 views
What is difference between ++i, i++ in C/C++?
posted Aug 18, 2014

++i means pre-increment
EX if i=0;
++i;      O/P will b 1
++i        O/P will b 2
like that

and i++ for post increment
EX if i=0;
i++ O/P will b 0
i++ O/P will b 1
like that

1. i++ refers to post increment. It assigns the value first and then increments.
eg.- int x, i=10;
x = i++;
printf("x= %d i = %d\n",x,i);

The result will be x = 10 & i =11;

1. ++i refers to pre increment. First it increments and then assigns the value.
eg.- int x, i=10;
x = ++i;
printf("x= %d i = %d\n",x,i);

The result will be x = 11 & i =11;

Hope this helps!

The meaning is same for both c and c++.
++i means pre-increment and
i++ means post-increment

For better understanding see the example.

int main()
{
int x, y;
int i = 0;

x = ++i; // here pre-increment the value of i and then store it into x i.e (x = 1)

y = i++; // here post-increment the value of i after storing it into y, i.e (y = 1)
// to verify the above
printf("x = %d and y = %d\n", x, y);

return 0;
}

output :
x = 1 and y = 1