Click to See Complete Forum and Search --> : Diference between PostFix & Prefix?
VC++ - Beginner
11-09-2000, 03:27 PM
Hello there,
Can someone please tell me :
How do you diferentiate between POSTFIX ( i++ ) and PREFIX ( ++i),increment
and decrement operators?
Thank you,
VC++ Beginner
Luis Abreu
11-09-2000, 03:39 PM
If you use them in an expression you'll obtain diferent results, but
if they're used alone, then there's, no diference on using one or
another.
For instance suppose you have these instructions:
i++;
++i;
Since the expression is only i++ or ++i, you'll obtain the same
result. However in this situation:
SIT 1
int a;
int i = 20;
a = ++i;
SIT2
int a;
int i = 20;
a = i++;
In SIT1, you'll get a = to 21 and i = 21( before being copied, i is
incremented by the prefix operator) and in SIT 2 a = 20 and i = 21
(postfix operator);
Conclusion: postfix increments after using the variable in an
expression. The prefix increments first and then uses the result in
the expression.
Hope this helps,
Luis Abreu
On 9 Nov 2000 12:27:56 -0800, "VC++ - Beginner"
<beginner@learningC++.com> wrote:
>
>Hello there,
>
>Can someone please tell me :
>
>How do you diferentiate between POSTFIX ( i++ ) and PREFIX ( ++i),increment
>and decrement operators?
>
>Thank you,
>
>VC++ Beginner
ralph
11-09-2000, 05:35 PM
Are talking about overloading the prefix and postfix operators?
In that case you need to create two "overloads".
class CJunk
{
...
public:
CJunk operator++()
{
// prefix routine stuff goes here
};
CJunk operator++( int )
{
// postfix routine stuff goes here
};
}
devx.com
Copyright Internet.com Inc. All Rights Reserved