Search code examples
clinkerincludec-preprocessorcompiler-directives

C programming directives #include<stdio.h> printf


I have that simple hello world program. First row it says #include <stdio.h>.

I googled it and it tells basically the preprocessor to define the functions for input/output.

First question:
I read that the actually code of the function first compiled to an object file. So if I say #include <foo.bar> it automatically linkes that object file?

Second question:
When I removed the include, the program still works... I mean the printf statement... why?


Solution

  • printf() is located in standard C library and linker links standard library to your program.

    So any standard functions will not be any linking problems.

    If you compile the program without #include<stdio.h> using gcc you will get the warning.