It looks like you're new here. If you want to get involved, click one of these buttons!
#include<stdio.h>
#include<conio.h>
void main()
{
int a=1;
printf(\"%d%d%d\",a,++a,a++);
getch();
}
int a, b = 5, c;
a = b++; // a = 5, b = 6
c = ++b; // c = 7, b = 7
...I'll be surprised to see how many people get this.
[spoiler]void main in many compilers should NOT compile (it doesn't in code-blocks) - It isn't part of the C standard. The code-block wants to return an integer... but datatype isn't specified (int main()). int main(void) would probably be the most correct code.
Compile the code with the change, mine returned 331 - yes this is compiler dependent. %d is a specifier (it formats the output for printf into a single character (I believe)). The answer should be... 221.
Increment/decrement being the suffix and the prefix.int a, b = 5, c;
a = b++; // a = 5, b = 6
c = ++b; // c = 7, b = 7
The printf statement is read into the stack from stack from left to right just so you know ;)
Ironically - just a mention - some beginners books teach void main() :\
A C coder will i'm sure correct me if i'm wrong about anything.[/spoiler]
0x080483c4 <+0>: push %ebp
0x080483c5 <+1>: mov %esp,%ebp
0x080483c7 <+3>: and $0xfffffff0,%esp
0x080483ca <+6>: sub $0x20,%esp
0x080483cd <+9>: movl $0x1,0x1c(%esp) # assignment of a
0x080483d5 <+17>: mov 0x1c(%esp),%edx # moving a = 1 to edx
0x080483d9 <+21>: addl $0x1,0x1c(%esp) # value at (0x1c)(%esp) incremented by 1 -> = 2
0x080483de <+26>: addl $0x1,0x1c(%esp) # value at (0x1c)(%esp) incremented by 1 -> = 3
0x080483e3 <+31>: mov $0x80484d0,%eax
0x080483e8 <+36>: mov %edx,0xc(%esp) # value of edx copied to location 0xc(%esp) [edx = 1 at this time
0x080483ec <+40>: mov 0x1c(%esp),%edx # copies value at 0x1c to edx [making edx = 3]
0x080483f0 <+44>: mov %edx,0x8(%esp) # puts value of edx [3] to 0x8(%esp)
0x080483f4 <+48>: mov 0x1c(%esp),%edx # copies value at 0x1c to edx [making edx = 3 still]
0x080483f8 <+52>: mov %edx,0x4(%esp) # puts value of edx to 0x4(%esp)
0x080483fc <+56>: mov %eax,(%esp)
0x080483ff <+59>: call 0x80482f4 <printf@plt>
0x08048404 <+64>: leave
0x08048405 <+65>: ret
0x1c = 3
0x18 = ~
0x14 = ~
0x10 = ~
0x0c = 1 ######################################################
0x08 = 3 # Arguments of a function are pushed with last first #
0x04 = 3 ######################################################
0x00 = ~