to make the question clear, I wrote some test code:
#include <stdio.h>
#include <string.h>
char *foo(int a) {
printf("%d\n", a);
static char string[2];
string[0] = a > 0? '1' : '0';
string[1] = '\0';
return string;
}
int main(void) {
printf("%s\t%s\n", foo(1), foo(0));
return 0;
}
Running the code gives output like this:
0
1
1 1
I have two questions here: 1. Why is 0 printed before 1? in main's printf function, the second foo is executed before the first? Is this a defined behaviour or just by chance. 2. Why is the final output 1, 1? The expected result should be 1, 0.