So I am a beginner in C and I have been following a book Primer Plus 6th edition.While I was running my program I noticed something really strange, compiler is not working as it is supposed to, for example
int main(){ one_three(); getchar(); return 0;}void one_three(void){ printf("one\n"); two(); printf("three");}void two(void){ printf("two\n");}
this is my code, there are many errors as no function prototype declarations and not including header files, but some how the output is produced only by giving warnings, i dont think this should happenNOTE I HAVE INTENTIONALLY REMOVED FUNCTION PROTOTYPE DECLARTAIONS AND INCLUDING HEADER FILES
output is :
review1.c: In function 'main':review1.c:2:5: warning: implicit declaration of function 'one_three' [-Wimplicit-function-declaration] 2 | one_three(); | ^~~~~~~~~review1.c:3:5: warning: implicit declaration of function 'getchar' [-Wimplicit-function-declaration] 3 | getchar(); | ^~~~~~~review1.c:1:1: note: 'getchar' is defined in header '<stdio.h>'; did you forget to '#include <stdio.h>'?+++ |+#include <stdio.h> 1 | int main(){review1.c: At top level:review1.c:7:6: warning: conflicting types for 'one_three' 7 | void one_three(void){ | ^~~~~~~~~review1.c:2:5: note: previous implicit declaration of 'one_three' was here 2 | one_three(); | ^~~~~~~~~review1.c: In function 'one_three':review1.c:8:5: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration] 8 | printf("one\n"); | ^~~~~~review1.c:8:5: warning: incompatible implicit declaration of built-in function 'printf'review1.c:8:5: note: include '<stdio.h>' or provide a declaration of 'printf'review1.c:9:5: warning: implicit declaration of function 'two' [-Wimplicit-function-declaration] 9 | two(); | ^~~review1.c: At top level:review1.c:13:6: warning: conflicting types for 'two' 13 | void two(void){ | ^~~review1.c:9:5: note: previous implicit declaration of 'two' was here 9 | two(); | ^~~review1.c: In function 'two':review1.c:14:5: warning: incompatible implicit declaration of built-in function 'printf' 14 | printf("two\n"); | ^~~~~~review1.c:14:5: note: include '<stdio.h>' or provide a declaration of 'printf'one twothree
those last three lines "one" two three is the outputPlease help, i am using this compiler
Image may be NSFW.
Clik here to view.
I expect it to output errors when it has to and not add stuff itself, so that i could learn by my mistakesusing visual studio code with extensions : C/C++ by microsoft, Code runner