So I was writing a C function but I had a hard time debugging, and eventually I found the problem was an 'empty' if statement. However, I suspect it isn't empty, as there were no curly braces, and it might just pass newlines until it finds a line of code. If this line is a return, I might think the return is now 'inside' the if. If this is the case, what would happen if the 'if' condition is false? What would the function return? In my original function, it would just return 15 or 16 (when the condition was false) instead of the expected 0 or 1. I leave here a simplified code of what I'm talking about. In this case something stranger happens. It seems it will always return 1 no matter the 'if' condition is satisfied or not. And if we uncomment the 'return 3;' the code works as expected given that the first return would be inside the 'if'. What exactly is happening here?
#include <stdio.h>
int testIf(void){
if(0)
return 1;
//return 3;
}
int main(void){
printf("%d\n", testIf());
return 0;
}