1.

Why n++ executes faster than n+1 ?

Answer»

n++ being a unary operation, it just needs one variable. Whereas, n = n + 1 is a BINARY operation that adds overhead to take more time (also binary operation: n += 1). However, in modern platforms, it depends on few things such as PROCESSOR architecture, C compiler, usage in your code, and other factors such as hardware problems.

While in the modern compiler even if you write n = n + 1 it will get CONVERTED into n++ when it goes into the optimized binary, and it will be EQUIVALENTLY efficient.



Discussion

No Comment Found