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
Go To First  |  Previous Question  |  Next Question 
 C  |  Question 417 of 437    Print  
Increment Operator
Explain why p++ is faster than p+1?


  
Total Answers and Comments: 5 Last Update: September 20, 2008     Asked by: amar_keerthi07 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
June 04, 2008 01:30:58   #1  
chandrakala Kempapura Member Since: June 2008   Contribution: 3    

RE: Increment Operator
Hi Amar,
      Increament opetaotrs is an unary operator. which operate on single operand.
But + ia an binary operator, needs at least  2 oprands to execute.

so always unary operators are faster than binary operators.

Regards
chandrakala

 
Is this answer useful? Yes | No
June 30, 2008 07:26:54   #2  
hiralbest Member Since: June 2008   Contribution: 1    

RE: Increment Operator
p++ is a macro and inbuit function.and the + is binary operator.
so p++ is faster than p+1.

 
Is this answer useful? Yes | No
July 12, 2008 04:45:34   #3  
kaivalya1989 Member Since: May 2008   Contribution: 5    

RE: Increment Operator
p++ is a unary operator that is why it is fast
as it operates on only one operand
on the other hand p+1
+ is a binary operator that is why it is slower as compared to ++

 
Is this answer useful? Yes | No
July 12, 2008 04:52:48   #4  
kaivalya1989 Member Since: May 2008   Contribution: 5    

RE: Increment Operator
static memory allocation :
the memory allocation is done at the time of compilation itself..
it is known as static because this allocation cannot be changed is less memory or more memory is needed at the time of execution of program...
in this type good memory management is not achieved as many times memory loss takes place or shortage of memory rakes place....
dynamic memory allocation:
the memory allocation is done at the run time of program...
as per needed... thus good memory management is achieved
this is done by using some inbuilt functions
malloc(),calloc(),realloc(),free() etc
for using these functions we need to include alloc.h........

 
Is this answer useful? Yes | No
September 19, 2008 13:18:03   #5  
pirabid Member Since: May 2008   Contribution: 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

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape