Sunday, July 12, 2009

Why pre-increment operator is faster than post-increment in C/C++ language ?

This is a myth. Most compilers produce exactly the same code for both operators (if the result of the expression is not used, as in "a++;").





If the result of the operator is used (as in "b=a++;"), the post-increment expression may be slower on some platforms because it must keep the old value around while updating the variable. But the difference is too small to worry about. Anyway, in this case the two operators produce different results so you are not free to choose.

Why pre-increment operator is faster than post-increment in C/C++ language ?
Though both have there seperate use, postincrement is slow because it use to implemement assignment first and will increment in the next step and when the command over by ';' operator then it increments it..this is the reason..


No comments:

Post a Comment