You will get a warning
implicit declaration of function 'getch'
because you do not have a header declaring getch . The standard headers <stdio.h> or <stdlib.h> do not declare such a function.
In fact, there is no function named getch in any standard C header.
Prior to the C99 standard, the C language allowed function calls without a visible declaration. Such a call will actually create an implicit declaration of the function that returns an int , and will accept the arguments of any (advanced) type that you actually passed.
Depending on this, it was never a good idea. You should always have the correct #include directive for the header, which declares any library function that you use in your program.
C99 rejected the "implicit int rule" and made any function call without a visible declaration of a violation of the constraint that requires diagnostics (this diagnosis is allowed as a non-fatal error.)
If you compile on Windows, if I remember correctly, there getch() function is declared in <conio.h> . If you want to use this function, you need to add #include <conio.h> to your program.
I do not recommend doing this; using getch() not necessary and makes your program not portable. In some Windows development environments, it is difficult to run βconsole programsβ (programs that print to standard output rather than creating a graphical interface); often starting such a program creates a temporary window that is destroyed as soon as the program ends. Calling the standard getchar() function getchar() another way to prevent a window from disappearing. Or you can execute the program from the command line, and its output will appear in your current command window.
If you are compiling into a UNIX-like system, there is another function called getch() declared in <curses.h> . I can compile and execute your program on Linux if I add -lcurses to the compiler command line. But you should not use this getch() function if you have not created a curses environment, and it is clear enough that you do not want to do this.
Ideally, the classic "hello world" program should be simple:
#include <stdio.h> int main(void) { printf("Hello world!\n"); return 0; }
How you run it and allow you to see that the result depends on your environment (which you did not tell us about).