# Post vs. Pre increment

Page 1 of 1

## 2 Replies - 12814 Views - Last Post: 30 August 2006 - 05:34 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=18201&amp;s=cfebe1e6919df8965701e30e2f9b8e04&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 venkateshpatchala

Reputation: 0
• Posts: 2
• Joined: 29-August 06

# Post vs. Pre increment

Posted 29 August 2006 - 11:51 PM

what is the difference between post increment and pre increment?[color=#FF0000]
Is This A Good Question/Topic? 0

## Replies To: Post vs. Pre increment

### #2 Louisda16th

• dream.in.assembly.code

Reputation: 15
• Posts: 1,967
• Joined: 03-August 06

## Re: Post vs. Pre increment

Posted 30 August 2006 - 02:04 AM

mmm. well here's an example:
#include<stdio.h>
int main()
{
int a,b,c,d;
a=1;
b=1;
c=++a;
d=b++;
printf("%d\n %d\n %d\n %d",a,b,c,d);

return 0;
}

Now the output for this would be :
2
2
2
1

as u can see, in the case of ++a, 1st a is incremented then its value is asigned to c, in the 2nd case. 1st, b's value is assigned to d.
There's one more place which this makes a diff(there may be more. cant think of any right now ). Suppose:
int i = 0;
while (i++<10)
{
/*statements*/
}

and

int i = 0;
while (++i<10)
{
/*statements*/
}

in the first case, i is first compared with 10 then it is incremented. In the second case, i is 1st incremented then its compared. Hope u got it
Similarly u have post and pre decrement using '--'.

This post has been edited by Louisda16th: 30 August 2006 - 02:05 AM

### #3 born2c0de

• printf("I'm a %XR",195936478);

Reputation: 186
• Posts: 4,673
• Joined: 26-November 04

## Re: Post vs. Pre increment

Posted 30 August 2006 - 05:34 AM

Great Examples, Louisda16th.

Also remember that using these operators in arguments of Macros result in compiler-dependent results.