IT Community - Software Programming, Web Development and Technical Support

n++

This is a discussion on n++ within the C and C++ Programming forums, part of the Software Development category; Hi all, why n++ executes faster than n+1? Sabita...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C and C++ Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 07-20-2007, 06:53 AM
simplesabita simplesabita is offline
D-Web Sr.Programmer
 
Join Date: Jul 2007
Posts: 170
simplesabita is on a distinguished road
Default n++

Hi all,

why n++ executes faster than n+1?


Sabita
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-20-2007, 07:28 AM
Karpagarajan Karpagarajan is offline
D-Web Analyst
 
Join Date: Mar 2007
Posts: 299
Karpagarajan is on a distinguished road
Smile Re: n++

Hi,
Possibly the most well known operator in C++; ++ is a unary operator that can be applied to variables and increments the value they hold. For example often for loops have, as their increment-expr something like:-

counter++


why this is faster than the normal increment statement (n++ instead of n=n+1) , because normally the C++ compiler will compile or execute a statement from left to right compilation. Say for an example

n=n+1;

the compilation is like this
  1. first take 1 into memory
  2. take + operator add compilation
  3. Take n and looking for value
  4. Do the caluculation the variable (n+1)=>(n=10,n+1=11)
  5. And finaly add to the n memory.
But whereas in n++, the compiler will do
  1. Take ++ operator
  2. Take the n memory value, and do the calculation, assign to n memory
This is why the ++ is faster than the normal calculation(increment). Hope you got the information.

thanks
__________________
Karpagarajan. R
Necessity is the mother of invention
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -7. The time now is 04:25 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0