Could you please explain this code segment
Ineiev
ineiev@gmail.com
Thu Dec 17 08:46:00 GMT 2009
On 12/17/09, W.H. Kalpa Pathum <callkalpa@gmail.com> wrote:
> Could you please explain how the output differs (when assigned to the
> variable b and in printf statement) and the way the compiler executes
> each segment of the variable?
>
> int main(){
> int a = 10;
> int b = (++a) + (++a);
> printf("%d %d %d %d\n", b, a++, a, ++a);
> printf("%d %d %d %d\n", ++a + ++a, a++, a, ++a);
The program evaluates the arguments first and calls
printf then.
You can't do such things if you want to rely on the result, because
the order of the arguments evaluation is implementation-specific (to
begin with).
More information about the Gcc-help
mailing list