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:  Increment Operator

Answer: Explain why p++ is faster than p+1?


September 09, 2008 13:18:03 #5
 pirabid J2EE Expert  Member Since: May 2008    Total Comments: 1 

RE: Increment Operator
 
This has to do with the processor, memory read cycles, and processor instructions.

All processors have separate increment/decrement instructions for increment/decrement operations. Consequently, when increment/decrement operation has to be carried out only one operand needs to be accessed and that requires 1 memory read cycle and then it goes into the CPU register and then it's incremented/decremented. But for addition operation we require two memory read cycles (because two operands are involved) and then the addition/subtraction operation is applied. This is why increment/decrement is faster than addition/subtraction.

Regards
     

 

Back To Question