|
|
why n++ executes faster than n+1? - C
|
Views : 619
|
|
Tagged in : C
|
|
|
Report This Scrap as Inappropriate We request you to choose the appropriate categroy and subcategory that suits your
objectionable concern about the scrap, So that our team can review and find out whether it violates our Guidelines or the
scrap is not suitable for all viewers.
|
The expression n++ requires a single machine instruction such as INR to carry out the increment operation whereas, n+1 requires more instructions to carry out this operation.
The question is meaningless since the two aren't equivalent.
n++ modifies n.
n+1 does not.
If the purpose is to increment n by one and n is a register variable, the two are almost the same in processor resources, except that the result of n+1 requires the compiler to allocate a second register for the intermediate result.
Also, the first answer is incorrect. The 'INC EAX' instruction in an x86 CPU is no faster than an 'ADD EAX,1' instruction and the only benefit is to reduce code space. |
|
By Vijayaprasad, On - 2010-02-16 |
|
|
|