Which is faster post increment or pre increment ? and in
which cases should u use either - to increase speed?
Answers were Sorted based on User's Feedback
Answer / 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 |
Answer / mms zubeir
The above answer seems to be correct but for normal cases
also the behavior is as explained, it is not only for
overloaded case.
A little deeper, since a temporary object is introduced to
swap older and newer values, extra copying is required
which swallow its own CPU time. So the post increment
operator is a bit slower.
But this difference is feeble.
| Is This Answer Correct ? | 16 Yes | 1 No |
What is overriding in oops?
c++ is a pure object oriented programming or not?
Can abstract class have normal methods?
Input: enter the value:1234 output: 1 2 3 4 write a program to get above output.....
4 Answers Bally Technologies, IBM, SoftSol,
string is a class or data type in java?
There are 2 classes defined as below public class A { class B b; } public class B { class A a; } compiler gives error. How to fix it?
explain dynamic binding by drowing
why to use operator overloading
i have to create a view in SQL as like in ORACLE DATA EXPRESS EDITION
In the following declaration of main, "int main(int argc, char *argv[])", to what does argv[0] usually correspond? 1) The first argument passed into the program 2) The program name 3) You can't define main like that
What is the benefit of oop?
Polymorphism with an example?