- | Compare between i++ and ++i (Prefix inrement vs Post Fix Increment) | |||||||||||
Basic Differance C Level\Enviorment |
Lets review the Basic Example (Example 1) at first it looks like the operators are identical however we will review this in detail. DIfferance 1 - Operations increment at different times. Differance 1 (Example 2) - the Postfix increment now showd in the printf() The reason is that postfix Increment happen after assignment performed, its important to pay attention to this as it can easily misslead DIfferance 1 (Example 3) - that posfix increment may mislead. What will be i value in line 10? the operator will actually not do anything... the ++ increment the RValue after it been assign (with =) to i from Left (LValue) so the increment done the RValue that not in use anymore and therefore vanished. DIfferance 1 (Example 4) - that posfix not applay from function (by Value) Note: because i passed by value the original 'i' from main() is not expected to be incremented.. DIfferance 1 (Example 5) - that posfix not applay from function (by refferance) Note: because i passed by refferance the i is expected to be incremented, but because of postfix inrement it will not return from incPost |
Differance in ASM Level |
Differance 2 - Operation work Differantly at Instruction Level (ASM). Lets review the Basic Example again (Example 1) now lets recompile it again to see the ASM commands.
|