##### Lecture on Post & Pre Increment Operators
Content covered:

Post and Pre Increment Operators.

Consider a variable : $\text{count} = 5$

Post Increment: We write post increment as $count++$

Pre Increment : We write pre increment as $++count$

Both of the above statements increase the value by 1:

$++count = count++ = count +1$

The diferrence between post and pre increment operations is observed when we assign them to be stored into a variable.

Let us consider an example below:

$\underline{\text{Case-I}} : \ \text{Post Increment}$

Consider the following block of code:

$count = 5; \\ p = count++; \\ \text{printf("%d %d", p, count );} \\ \underline{\text{O/P}}: \\ \text{5 6}$

Here, first the value of $count$ is stored in $p$, then the value is incremented, result is that the final value is : $p=5 \ \ and \ \ count = 6$

$\underline{\text{Case-II}} : \ \text{Pre Increment}$

Consider the following block of code:

$count = 5; \\ p =++ count; \\ \text{printf("%d %d", p, count );} \\ \underline{\text{O/P}}: \\ \text{6 6}$

Here, first the value of $count$ is incemented then stored in $p$, result is that the final values are :  $p=6 \ \ and \ \ count = 6$

Similarly , Post/Pre Decrement operation also works in the same way. The only difference is that instead of incrementing by 1 , we decrement the value by 1.

More Less