Pages

29 January 2011

Order of argument evaluation in C, left-to-right or right-to-left?

Suppose you have written the below codes:

#include
 
  int global_a = 10;
 
  int increase(void)
  {
       return global_a += 10;
  }

 int main(void)
 {
      printf("%d,%d\n", increase(), global_a);
 }
 
And you compile it, what output would you expect? "20,10"? or "20,20"? 
 
I was thinking "surely it is 20,20!". But this post says both are right! Wow.....
Note: the original poster was actually comparing GCC to TCC (Tiny C Compiler).

regards,
 
Mulyadi.

No comments: