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

Do you know about multiple inheritance?

639


write a program to enter a string like"sunil is a good boy and seeking for a job" not more than 10 characters including space in one line,rest characters should b in other line.if the next line starts from in between the previous word,then print whole word to next line.

1793


What makes a language oop?

596


What is abstraction encapsulation?

657


I have One image (means a group photo ) how to split the faces only from the image?............ please send the answer nagadurgaraju@gmail.com thanks in advace...

1626






Can a destructor be called directly?

599


Whats oop mean?

590


Can enum be null?

587


how to get the oracle certification? send me the answer

1670


Why do we need oop?

671


assume the program must insert 4 elements from the key board and then do the following programs.sequential search(search one of the elements),using insertion sort(sort the element) and using selection sort(sort the element).

1662


class type to basic type conversion

1835


What are benefits of oop?

637


What is use of overloading?

608


What is the difference between abstraction and polymorphism?

617