int a = 5;
printf("%d %d %d \n",a++,a++,++a);
it prints 7 6 8
im using gcc compiler,
how it evaluates....
Printable View
int a = 5;
printf("%d %d %d \n",a++,a++,++a);
it prints 7 6 8
im using gcc compiler,
how it evaluates....
The order in which the program executes the parameters to a function is unspecified.
Relying on a specific order is Undefined Behaviour.
Don't rely on specific order.
Don't write code with Undefined Behaviour.
Code:int a = 5;
printf("%d %d %d\n", a + 1, a + 2, a + 3);
a = 8;
it prints 7 6 8Code:
int a = 5;
printf("%d %d %d\n", a + 1, a + 2, a + 3);
im using gcc compiler,
how it evaluates....
Err... you probably read the output wrongly. In that second code snippet, no matter what order of evaluation is used, the result should still be 6 7 8
yes,the correct one is
printf("%d %d %d \n",a++,a++,++a);
It could print 7 6 8
it could print yellow
it could format your hard drive
it could send money from your bank account to mine
Don't write Undefined Behaviour!
To see what your compiler, with your options, did: try seeing the assembler output (hint: gcc -S).
Note the output may be different if you compile in the afternoon, or change the optimization level, or your teacher is looking, or ... ... ...
in my machine it prints 7 6 8
It's a regular topic.
http://cboard.cprogramming.com/c-pro...increment.html