Videos
What is the C Hello World Program?
Why is the C Hello World Program important?
What are some different ways to write the C Hello World Program?
Case 1: your book is wrong. Removing \n will never raise any error. \n means newline which will print a new line after Hello World.
Case 2: May be you are not building the code again, because without including the stdio (means standard input/output) you may not invoke printf() function if you use newer C standards (C99, C11). Read more about stdio.h.
Note that, in pre C99 standard if you remove the prototype (#include <stdio.h>) C will automatically provide an implicit declaration for a function. Which will look like this:
int printf();
means, it will take any number of arguments and return int. But in C99 implicit deceleration were removed. So most probably your compiler does not confront C99.
Take a look here, compile fine!
Read more about implicit declarations in c.
EDIT: As AnT mentioned in the comment, removing #include<stdio.h>, the call to printf will "compile" in pre-C99 version of language. However, the call will produce undefined behavior. Variadic functions (like printf) have to be declared with prototype before the call even in C89/90. Otherwise, the behavior is undefined.
Your program already contains an error. Functions in modern C have to be declared with an explicitly specified return type. Your
main()is declared without a return type, which has been illegal since C99.There are different kinds of "errors". Some errors cause compiler to issue a diagnostic message. Some errors simply make your program behave unpredictably at run time (exhibit undefined behavior). The latter might be harder to detect, since "unpredictable" might look perfectly fine on the first sight.
In your case removing
#include <stdio.h>will trigger a diagnostic message in C99-compiliant compiler, but will lead to mere undefined behavior in C89/90 compiler. Undefined behavior might still produce the same screen output as before.