Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Re: Unpredictab...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 12 Topic 45818 of 47034
Post > Topic >>

Re: Unpredictable nature of increment operators

by Martin York <Martin.YorkAmazon@[EMAIL PROTECTED] > May 9, 2008 at 10:11 AM

On May 8, 5:16 pm, bintom <binoythomas1...@[EMAIL PROTECTED]
> wrote:
> Why doe the following C++ code behaves as it does?
>
> int i;
>
> i=1;            cout << (++i)++;          Output: 2
> i=1;            cout << ++(++i);          Output: 3
> i=1;            cout << (i++)++;          Output: Error. LValue required
> i=1;            cout << ++(i++);          Output: Error. LValue required

Because code like that is so hard to read you would never actually
write it!

Also remember that it is illegal to modify a variable more than once
within the same expression [undefined behavior I believe](somebody
with a copy of the standard will be able to quote you chapter an verse
and the actual definition rather than my layman's wording).
 




 12 Posts in Topic:
Unpredictable nature of increment operators
bintom <binoythomas110  2008-05-08 17:16:56 
Re: Unpredictable nature of increment operators
Ian Collins <ian-news@  2008-05-09 12:17:58 
Re: Unpredictable nature of increment operators
Martin York <Martin.Yo  2008-05-09 10:11:08 
Re: Unpredictable nature of increment operators
"Victor Bazarov"  2008-05-09 13:21:26 
Re: Unpredictable nature of increment operators
Jerry Coffin <jcoffin@  2008-05-10 08:47:59 
Re: Unpredictable nature of increment operators
James Kanze <james.kan  2008-05-10 07:08:42 
Re: Unpredictable nature of increment operators
Jerry Coffin <jcoffin@  2008-05-10 09:01:10 
Re: Unpredictable nature of increment operators
"Bo Persson" &l  2008-05-11 10:56:59 
Re: Unpredictable nature of increment operators
Jerry Coffin <jcoffin@  2008-05-11 09:05:09 
Re: Unpredictable nature of increment operators
Old Wolf <oldwolf@[EMA  2008-05-11 02:14:44 
Re: Unpredictable nature of increment operators
James Kanze <james.kan  2008-05-11 09:09:34 
Re: Unpredictable nature of increment operators
James Kanze <james.kan  2008-05-11 09:19:28 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Jul 26 3:06:18 CDT 2008.