i have just started learning postfix and prefix notations. i was wondering if there is tutorial or something with regards to it here. i was also wondering if there are conversions from postfix to prefix and vice versa. is it available?

10 Years
Discussion Span
Last Post by Duoas

In C and C++ the only time it makes a difference is with the increment and decrement operators, which each come in two forms: postfix and prefix.

Here we have an integer: int a = 42; Let's play with it: cout << a << endl; prints 42 cout << ++a + 1 << endl; prints 44 cout << a << endl; prints 43
In this example, a was incremented before the expression was evaluated. (The entire cout statement.) This is prefix: the increment is done first. cout << a << endl; prints 43 cout << a++ + 1 << endl; prints 44 cout << a << endl; prints 44
In this example, a was incremented after the expression was evaluated. This is postfix: the increment is done last.

There is a caveat. For each distinct variable, you cannot use more than one increment or decrement operator in the same statement. Hence: cout << ++a++ << ++a << endl; BAD!
is likely to get you a random number.

Hope this helps.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.