Increment Operator

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

Questions by amar_keerthi07   answers by amar_keerthi07

Showing Answers 1 - 15 of 15 Answers

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

  Was this answer useful?  Yes

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........

  Was this answer useful?  Yes

pirabid

  • Sep 19th, 2008
 

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

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions