By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,562 Members | 1,222 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,562 IT Pros & Developers. It's quick & easy.

postfix and prefix

P: n/a
How can we implement operator ++ as postfix in prefix?

thanks
Oct 6 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Oct 6, 2:01*pm, puzzlecracker <ironsel2...@gmail.comwrote:
How can we implement operator ++ as postfix in prefix?

thanks
Not really sure what you are asking, but the ++ operator can be
applied in front of a variable or behind it. If in front, the value is
incremented before the value is "looked at". If after, the value isn't
incremented until after it is "looked at".
Oct 6 '08 #2

P: n/a
puzzlecracker kirjoitti:
How can we implement operator ++ as postfix in prefix?

thanks
In C

int a=10;
printf("%d\n", ++a);

prints 11 and

int a=10;
printf("%d\n",a++);

prints 10

(and on both cases, a is 11 after the code).

The first ++ is called prefix and the second postfix.

On C++ if you like to add ++ to your own classes, you have to implement
separate operators for postfix and prefix ++ operators. However, this
article : http://devhawk.net/2003/07/10/Operat...ding+In+C.aspx
claims that for C# you have to implement only one operator, the compiler
handles the difference.

--
Arto Viitanen
Oct 7 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.