printf() : header file not required???

in C language we make use of printf() function for standard output. from all the resources i have referenced, they say you should include <stdio.h> before using printf(). however i tried using printf without including any header file and it worked perfectly.

For example i tried this:

/*here i have not included any header file.. just straight away started with main()*/
void main()
  printf("hello world !!!");

and it gives output hello world !!!

so it means we do not need to include anything for using printf()
so where is the definition of printf() ???
You are using an old C-compiler that follows the C89 Standard where functions by default have return type int.
The compiler supposes that the function has declaration

int printf();

The compiler determines types and number of parameters looking its call statement. After that the linker search the name printf in one of its library and use it.
It is unsafe approach.
Last edited on
Topic archived. No new replies allowed.