Possible Duplicate:
Parameter evaluation order before a function calling in C
For the below code I expected the output to be 20 and 76 but instead 75 and 21 is comming as output .Please explain why is so.
#include<stdio.h>
unsigned func(unsigned n)
{
unsigned int a =1 ;
static unsigned int b=2;
a+=b; b+=a;
{
unsigned int a=3;
a+=b; b+=a;
}
//printf("%d %d ",a,b);
return (n+a+b);
}
int main()
{
printf("%d %d\n",func(4),func(5));
return 0;
}
The order of evaluation of expression is
unspecified behaviour
hencefunc(4)
andfunc(5)
may be called in different order as you supposed toYou might like to visit it for more
Compilers and argument order of evaluation in C++
Parameter evaluation order before a function calling in C
func(5) is getting executed first :
Values of variables after executing func(5) :
Since, b is static, the values after executing func(4):