Hi,
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?

Recommended Answers

All 2 Replies

Read books. You qustion is not ver goo for understanding.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.