# Post vs. Pre increment

Page 1 of 1

## 2 Replies - 12737 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=575356390b4a12e3cad40b94dc90bafa&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: 184
• 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.

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }