Consider this simple program.
$ cat fails.c #include <stdio.h> int main(){ int i = 10; if (i == 10) int j = 11; return 0; }
This fails to compile by indicating this error:
$ gcc fails.c fails.c: In function 'main': fails.c:7:3: error: expected expression before 'int' int j = 11; ^
But this goes very well:
#include <stdio.h> int main(){ int i = 10; if (i == 10){ int j = 11; } return 0; }
I realized that working around is putting those {} . But I want to know why this is required.
Why does it behave this way when something like printf acceptable?
#include <stdio.h> int main(){ int i = 10; if (i == 10) printf("some text\n"); return 0; }
c
struggling_learner
source share