Why preincrement operator is faster than postincrement?




Answers were Sorted based on User's Feedback



Why preincrement operator is faster than postincrement?..

Answer / sanish joseph

the pre inc operator increments the value of that particular
variable on that line itself

the post inc operator increments the value of that
particular variable after going on the next line

in simple words

eg.

e=5; on this line value of e=5

e++; on this line value of e=5

++e; on this line value of e=7

Is This Answer Correct ?    27 Yes 9 No

Why preincrement operator is faster than postincrement?..

Answer / devesh patel

b/c preeincrement take one byte instruction & post
increment takes two instruction

Is This Answer Correct ?    16 Yes 7 No

Why preincrement operator is faster than postincrement?..

Answer / ranjeet garodia

Pre increment operator is use the concept of value by
reference that means it increment the actual object.

While post increment use call by value concept that is it
create the local object, operate on that, then it will
increment actual object, so takes time to create local
object

Is This Answer Correct ?    10 Yes 7 No




Why preincrement operator is faster than postincrement?..

Answer / shakti singh khinchi

Because post increment operator uses a temporary variable to
store the incremented value for a variable until it is used
in the next executed statement, whereas pre increment
operator not using any temp variable, it is just increase
that value at the time of execution using reference.

Is This Answer Correct ?    3 Yes 1 No

Why preincrement operator is faster than postincrement?..

Answer / puneet nagpal

postincrement did not increment unless it find ; so it increments after the end of statement. while the preincrement operator increment before the end of statement. so preincrement operator is faster than postincrement operator.
ex- a=10;
a++;value incremented after the end of statement but
at this point value is 10.
a++;now the value is incremented to 11.
++a; preincrement incremented within the statement now
the value is 12.

Is This Answer Correct ?    1 Yes 0 No

Post New Answer



More C++ General Interview Questions

i want to know how to copy arrary without using any method or function. I have tried the below using System; class e4 { static void Main(string[] args) { int a,b; int[ ] m= new int[5]; int[ ] n= new int[5]; for(a=0;a<=4;a++) { Console.WriteLine("enter any value"); m[a]=Convert.ToInt32(Console.ReadLine()); m[a]=n[a]; } for(b=0;b<=4;b++) { Console.WriteLine(n[b]); } } } but it will give wrong result can anyone solve this problem

1 Answers   Reliance,


What does the following code do: int c=0; cout< a) Undefined *Updated* b) 01 c) 00

0 Answers  


program to print this triangle * * * * * *

12 Answers   Infosys,


Implement strncpy

3 Answers  


Const char *p , char const *p What is the difference between the above two?

0 Answers   TCS,






what is the order of initialization for data?

10 Answers   Wipro, TCS, Amazon,


Is there anything you can do in C++ that you cannot do in C?

1 Answers  


Which bit wise operator is suitable for turning off a particular bit in a number?

0 Answers  


Explain how a pointer to function can be declared in C++?

0 Answers  


If all is successful, what should main return a) 0 b) 1 c) void

0 Answers  


Write any small program that will compile in "C" but not in "C++"?

4 Answers  


Consider a c++ template funtion template<class T> T& Add(T a, T b){return a+b ;} if this function is called as T c = Add("SAM", "SUNG"); what will happen? What is the problem in the template declaration/ How to solve the problem.

7 Answers   Samsung, LG,






Categories