Insights Blog
-- Browse All Articles --
Physics Articles
Physics Tutorials
Physics Guides
Physics FAQ
Math Articles
Math Tutorials
Math Guides
Math FAQ
Education Articles
Education Guides
Bio/Chem Articles
Technology Guides
Computer Science Tutorials
Forums
Intro Physics Homework Help
Advanced Physics Homework Help
Precalculus Homework Help
Calculus Homework Help
Bio/Chem Homework Help
Engineering Homework Help
Trending
Featured Threads
Log in
Register
What's new
Search
Search
Search titles only
By:
Intro Physics Homework Help
Advanced Physics Homework Help
Precalculus Homework Help
Calculus Homework Help
Bio/Chem Homework Help
Engineering Homework Help
Menu
Log in
Register
Navigation
More options
Contact us
Close Menu
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Forums
Homework Help
Engineering and Comp Sci Homework Help
Assigning a variable using a unary operator
Reply to thread
Message
[QUOTE="pbuk, post: 6860927, member: 385977"] No you have this the wrong way round: prefix operators return (a reference to) the altered value, postifx operators return (a reference to a copy of) the value before alteration. [URL]https://en.cppreference.com/w/cpp/language/operator_incdec[/URL] No, see above. The key point to remember is that with the right settings the optimizer is clever enough to produce [i]exactly the same code[/i] for [code=cpp] accumulator += x[i]; i++; // Or ++i. [/code] as [code=cpp] accumulator += x[i++]; [/code] so there is [i]no point[/i] in doing the latter, follow the simple rule to [b]never use the return value of an increment/decrement operator[/b]. Some style guides go as far as to say don't use the increment/decrement operators at all - instead use [code=cpp] accumulator += x[i]; i += 1; [/code] (and of course with the right optimizer settings for production code this will again compile to exactly the same object code). [/QUOTE]
Insert quotes…
Post reply
Forums
Homework Help
Engineering and Comp Sci Homework Help
Assigning a variable using a unary operator
Back
Top