As others commented, this i=2+2*i++;
is undefined behavior. Please read the wikipage explaining it.
See this answer to understand a bit more about UB.
Then read Chris Lattner's blog entries What Every Programmer should know about Undefined Behavior.
To understand the actual behavior of your buggy C program, you need to dive into implementation details (and you don't want to). If you really want to understand what has happened when using GCC, you might compile your badub.c
program with gcc -fdump-tree-all -O -fverbose-asm -S badub.c
and then lose weeks of your time understanding the (hundreds) of badub.*
files that this compilation command produced. Is it worth your time?
The lesson is avoid UB at all cost
To help more about avoiding UB, recent GCC compilers are sometimes able to emit warnings about it. You should at least compile with gcc -Wall -Wextra -g
to get all warnings and debug info. Learn to use the debugger. Learn about various -fsanitize=
options to recent GCC. Learn and use valgrind
BTW, it is the year 2015. Don't use TurboC, which is non-standard compliant, not efficient, not giving good warnings, buggy, proprietary, compiler of the previous century. Use a good free software compiler (like recent GCC or Clang/LLVM. Both can give better code and better warnings -when asked to- than your old crappy TurboC...)
i = i++;
cannot be expected to have any particular result. See here stackoverflow.com/questions/949433/…