Which is faster post increment or pre increment ? and in
which cases should u use either - to increase speed?
Answer Posted / me
In normal cases where we use x++ or ++x for integer
variables in loops etc, both behave the same.
However, when we have classes that overload the ++
operator, it's faster to use the ++x rather than x++.
This is because when we do x++, a temporary object is
created to point to the original value, then the value is
incremented, and the pointer is updated and returned.
in case of ++x, just the value is incremented and pointer
to itself is returned. therefore ++x is faster in this case.
| Is This Answer Correct ? | 31 Yes | 1 No |
Post New Answer View All Answers
What exactly is polymorphism?
What is the real time example of inheritance?
write a C++ program for booking using constructor and destructor.
What is the full form of oops?
What is the difference between a constructor and a destructor?
How to improve object oriented design skills?
What is overloading in oop?
What causes polymorphism?
What is difference between multiple inheritance and multilevel inheritance?
What is the significance of classes in oop?
What is polymorphism programming?
What is the important feature of inheritance?
#include
Why is destructor used?
How many human genes are polymorphic?