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:  Register Relation

Answer: Why p++ is faster than p+1?


July 07, 2009 06:28:19 #3
 sahasranaman   Member Since: July 2009    Total Comments: 1 

RE: Register Relation
 

p++ is faster because on compilation, it gets translated to three machine
instructions, where as p=p+1 needs four machine instructions. All machine
instructions take the same time.


For p++, the instructions are:

mov ax,

inc ax

mov,

ax


For p = p+ 1, the instructions would be,

mov ax,

mov bx, 1

add bx

mov,

ax


This is why p++ is faster than p+1

     

 

Back To Question