c - Why Does x = a() + ab(); has different results in different machines? -


i have 2 functions in c programs. lets name them a() , a(). in in code use result in equation: take @ this:

int number = 2; int x;  int a(){     number += 3;     return number; }  int b(){     number *= 2;     return number; }  x = a() + b();  printf("%d", x); 

here expect 15 printed. 11. can explain this?

in statement,

x = a() + b(); 

the order in functions a() , b() called unspecified. there's sequence point before calling each function , after returning each function.

that means there 2 possible orders of calls:
1) a() first , b().
2) b() first , a().

in case (1), result 15 , in case (2), result 11. there's no undefined behaviour despite number being modified both functions side-effect of function calls.


Comments