int a = 5;
printf("%d %d %d \n",a++,a++,++a);
it prints 7 6 8
im using gcc compiler,
how it evaluates....
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
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
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 ... ... ...
Last edited by qny; 12-07-2012 at 06:00 AM.
in my machine it prints 7 6 8
It's a regular topic.
Post and Pre Increment
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.