brain teaser...
-
because
i++
is the post-incrementation, which mean that the incrementation is done at the end of the expression (herecout << i++ << i;
). by opposite,cout << ++i << i;
would have outputed11
andcout << i << ++i;
would have outputed01
. is that all clear ?
TOXCCT >>> GEII power
[toxcct][VisualCalc] -
It does not. In my compiler it outputs 01 and that is correct .
"Success is the ability to go from one failure to another with no loss of enthusiasm." - W.Churchill
-
Laffis wrote: why does it output 00? Because it just happened to. "Sequence points" are those placecs at the end of statements, full expressions, before a function is invoked, and right after it returns. In between sequence points, side-effects of operators may not have taken place, and values are indeterminate. The exact point at which that increment takes place is unknown and unspecified; only the sequence-point semantics need to be satisfied. This allows compilers to either increment in-place after makng a copy or make an incremented copy which does not have to be set until the value is next needed, which by definition is after the sequence point.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
-
:-D I am sure this will catch someone out there, me included. The end result will be machine specific, ie. undefined. I guess it is because different machine will prioritise ++ and << in different manner.
-
Laffis wrote: why does it output 00? Because it just happened to. "Sequence points" are those placecs at the end of statements, full expressions, before a function is invoked, and right after it returns. In between sequence points, side-effects of operators may not have taken place, and values are indeterminate. The exact point at which that increment takes place is unknown and unspecified; only the sequence-point semantics need to be satisfied. This allows compilers to either increment in-place after makng a copy or make an incremented copy which does not have to be set until the value is next needed, which by definition is after the sequence point.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
-
operators priority are not system dependant. the priority is defined by the compiler, and specified in the standard of C++ !!!
TOXCCT >>> GEII power
[toxcct][VisualCalc]