postfix/prefix notations

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jan 2008
Posts: 15
Reputation: johndory is an unknown quantity at this point 
Solved Threads: 0
johndory johndory is offline Offline
Newbie Poster

postfix/prefix notations

 
0
  #1
Jan 28th, 2008
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?
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 114
Reputation: zhelih has a little shameless behaviour in the past 
Solved Threads: 11
zhelih's Avatar
zhelih zhelih is offline Offline
Junior Poster

Re: postfix/prefix notations

 
-1
  #2
Jan 28th, 2008
Read books. You qustion is not ver goo for understanding.
An Apple a Day keeps a Doctor away!
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,953
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: postfix/prefix notations

 
1
  #3
Jan 29th, 2008
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.
Last edited by Duoas; Jan 29th, 2008 at 1:37 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC