Today I saw an anonymous behavior of the printf()
function.
Can anybody please tell me why its behaving so.
Is that the execution of functions inside printf()
is in reverse order?
Please explain this or share a helpful link.
MY CODE
#include <stdio.h>
int fun(){
static int c=15;c++;
return c;
}
int main()
{
printf("%d %d %d",fun(),fun(),fun());
}
Actual output : 18 17 16 Expected output : 16 17 18
EDIT 2: I more thing I noticed that its behavior is not only with functions but also with variables
#include <stdio.h>
static int c=15;
int fun(){
c++;
return c;
}
int main()
{
printf(" %d %d %d %d %d",c,fun(),fun(),fun(),c);
}
Actual output : 18 18 17 16 15 Expected output : 15 16 17 18 18
Thanks in Advance :)