You are here:

C/c programming--> pointers

Advertisement


Question
-------------------------
Followup To
Question -
i m using linux 9.0
this question is asked in the interview.
why preincrem,ent operator is faster than post increment operator?
Answer -
>why preincrem,ent operator is faster than post increment operator?
I don't think this is true!
Everything depends on the implementation and according to ANSI C standards, there is no difference in the speeds!

-ssnkumar

i m sorry to say that i m not satisfied with your answer .someone has told me that for preincrement implementation it passes value by reference but for postincrement operator it passes value by value thats why preincrement is faster than post increment.
hope u will reply soon
thanking you  

Answer
The concept of "passing by reference" itself is alien to C.
And the post/pre-increment are not functions, they are operators. So, both of them have to increment whatever value is sent to them.
If you understand the concept of passing by value, you will know that the value of the variable sent to the function will remain unchanged.
As you are thinking if post increment passes the argument as "pass by value", then the value should not change at all. But, on the contrary, it also changes the value of the argument!

-ssnkumar

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Narendra

Expertise

I can answer questions in C related to programming, data structures, pointers and file manipulation. I use Solaris for doing C code and if you have questions related to C programming on Solaris, I will be able to help better.

Experience

6.5

Organizations belong to
Sun Microsystems

Awards and Honors
Brain Bench Certified Expert C programmer.
Advanced System Software Certified

©2012 About.com, a part of The New York Times Company. All rights reserved.