Tag Archives: ++ in Left and Right

C Programming Tutorial – 18 – ++ in Left and Right:

Published by:

Note:

  • // ++ in left first add 1 to viable and then calculate the equation. 
  • // ++ in right first calculate the equation and then add 1 to viable .

Code:
—————————

#include <stdio.h>
#include <stdlib.h>

int main()
{

int IncResult, increment=5 , constant=4;

// ++ in left first add 1 to increment and then calculate the equation.
IncResult = ++increment *constant;
printf(“increment = %d and constant= %d so IncResult= %d \n”,increment ,constant ,IncResult );

// since we defined the variable previously so we do not need to define them again.

IncResult=0 , increment=5 , constant=4;

// ++ in right first calculate the equation and then add 1 to increment

IncResult = increment++ *constant;
printf(“increment = %d and constant= %d so IncResult= %d \n”,increment ,constant ,IncResult );

return 0;

}