Follow Our FB Page << CircleMedia.in >> for Daily Laughter. We Post Funny, Viral, Comedy Videos, Memes, Vines...


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

When not to use object oriented programming?

0 Answers  


program in c++ that can either 2 integers or 2 floating point numbers and output the smallest number

1 Answers   Anna University,


What is inheritance and how many types of inheritance?

0 Answers  


some one give d clear explanation for polymorphism

3 Answers  


What do you mean by pure virtual functions?

8 Answers  






Write pseudo code for push in a stack?

2 Answers   emc2,


what are the uses of C++

1 Answers  


why oops need in programming

7 Answers   TCS,


What is pointer in oop?

0 Answers  


Objective The objective of this problem is to test the understanding of Object-Oriented Programming (OOP) concepts, in particular, on encapsulation. Problem Description Create a program for managing customer’s bank accounts. A bank customer can do the following operations: 1. Create a new bank account with an initial balance. 2. Deposit money into his/her account. 3. Withdraw money from his/her account. For this operation, you need to output “Transaction successful” if the intended amount of money can be withdrawn, otherwise output “Transaction unsuccessful” and no money will be withdrawn from his/her account. Input The input contains several operations and is terminated by “0”. The operations will be “Create name amount”, “Deposit name amount”, or “Withdraw name amount”, where name is the customer’s name and amount is an integer indicating the amount of money. There will be at most 100 bank accounts and they are all created on the first month when the bank is opening. You may assume that all account holders have unique names and the names consist of only a single word. Output The output contains the transaction result of withdrawal operations and the final balance of all customers after some withdrawal and deposit operations (same order as the input). Sample Input Create Billy 2500 Create Charlie 1000 Create John 100 Withdraw Charlie 500 Deposit John 899 Withdraw Charlie 1000 0

0 Answers  


Why is abstraction needed?

0 Answers  


What does <> mean pseudocode?

0 Answers  






Categories