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



Which is faster post increment or pre increment ? and in which cases should u use either - to incr..

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

Which is faster post increment or pre increment ? and in which cases should u use either - to incr..

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

Which is faster post increment or pre increment ? and in which cases should u use either - to incr..

Answer / bakeur

the faster is pre increment

Is This Answer Correct ?    0 Yes 0 No

Which is faster post increment or pre increment ? and in which cases should u use either - to incr..

Answer / zuber

extreme stage

Is This Answer Correct ?    0 Yes 2 No

Post New Answer

More OOPS Interview Questions

What is the outcome of the line of code "cout<<abs(- 16.5);"? 1) 16 2) 17 3) 16.5

16 Answers   TCS,


explain dynamic binding by drowing

2 Answers   Cognizant,


They started with the brief introduction followed by few basic C++ questions on polumorphism, inheritance and then virtual functions. What is polymorphims? How you will access polymorphic functions in C? How virtual function mechanism works?

0 Answers  


What is the difference between the c++ & java?

2 Answers  


Out of 4 concepts, which 3 C++ Follow?

1 Answers   TCS,






difference between overloading and overridding

11 Answers  


Can you inherit a private class?

0 Answers  


What is Hashing and how is it done? Pictorial form?

2 Answers   emc2, Wipro,


What is polymorphism in oop example?

0 Answers  


What is the real time example of inheritance?

0 Answers  


Can an interface inherit a class?

0 Answers  


what is oops

4 Answers   DELL,


Categories