Maybe my answer (for a number) is useful to some extent:
you can control the response for a pointer
How it i++works at a low level.
int main(){
int i=0,j=0;
j=i++;
printf("%d %d",j,i);
}
You can parse it using a flag -Swith gcc (g++):
My codenamem.c
$ gcc -S m.c
It will create an assembly file m.s.
Read comments I added:
pushl %ebp
movl %esp, %ebp
andl $-16, %esp
subl $32, %esp
movl $1, 28(%esp) // i due to declarations
movl $0, 24(%esp) // j
movl 28(%esp), %eax // this two lines are j = i
movl %eax, 24(%esp)
addl $1, 28(%esp) // increment to i, i++
movl $.LC0, %eax
movl 28(%esp), %edx
movl %edx, 8(%esp)
movl 24(%esp), %edx
movl %edx, 4(%esp)
movl %eax, (%esp)
call printf
This is how it is executed =, and then ++. If ++- postfix.
How the compiler works:
(according to my compiler)
j = i ++.
:
j = i++;
( ):
j = ++
i++ i = i + 1
+ (post)
/ \
/ \
= 1
/ \
/ \
j i
CASE OF PREFIX ++ (++ i):
, j = ++i, :
++, =;
// abstract syntax tree for j = ++i
=
/ \
/ \
j \
+ (prefix)
/ \
/ \
i 1
j = ++i j=0 i=1 :
movl $1, 28(%esp) // i declaration
movl $0, 24(%esp) // j
addl $1, 28(%esp) // First Add 1 to i because i++ (before = perform)
movl 28(%esp), %eax // Below two steps: = performed j = i
movl %eax, 24(%esp)