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


Please Help Members By Posting Answers For Below Questions

Write a java applet that computes and displays the squares of values between 25 and 1 inclusive and displays them in a TextArea box

2038


What is overloading in oops?

598


What is an example of genetic polymorphism?

653


What is object in oop with example?

707


What is polymorphism explain its types?

688






What is interface in oop?

664


What are different oops concepts?

579


Can destructor be overloaded?

602


What does it mean when someone says I oop?

587


What is constructor in oop?

591


What is the use of oops?

625


Plese get me a perfect C++ program for railway/airway reservation with all details.

3431


write a program to find 2 power of a 5digit number with out using big int and exponent ?

1899


What are the benefits of polymorphism?

627


What are the types of abstraction?

561