GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  GeekInterview.com  >  Interview Questions  >  Programming  >  C

 Print  |  
Question:  Does ++p faster than p++?



July 07, 2008 14:47:28 #2
 Jaya_Kaja CRM Expert  Member Since: July 2008    Total Comments: 3 

RE: Does ++p faster than p++?
 

Between ++p & p++ , there is no diff in terms of speed of execution .because both are of unary . But there is a diff in the evaluation of an expression by using these unary operations.

++p - First the value of p gets incremented by one & then the incremented value will be used in the expression for further evaluation.
p++ - First the value of p is used in the expression & then the value of p will get incremented by one .

For eg :

a) p= 10;


val = ++p * 100 ;

Here val = 1100;

p = 11;

b) p=10;
val = p++ * 100;
Here val = 1000;
p =11;

- Jayalakshmi Kaja

     

 

Back To Question