In article <49*************************@posting.google.com> ,
vi*******************@yahoo.com (Amit) wrote:
Which is more efficient and why?
p++ or ++p.
The short answer to this is: Write two programs, measure their execution
times. Try p += 1 and p = p + 1 as well. Can you measure any difference?
Does it matter?
The real answer is: If you worry which one is more efficient, then you
shouldn't worry about efficiency at all. You should worry about writing
code that does what it is supposed to do and that is readable, so
everyone reading the code knows that it does what it is supposed to do.
If you run into a situation where efficiency is important (for example:
You lose customers because it is too slow, or you get complaints about
the speed), then you need to learn about algorithms, profiling,
profiling, algorithms and profiling. Changing p++ to ++p won't get you
anywhere.