The library header files contain only the declarations of functions. So, how exactly does the function run when we call the library functions?
Ex: int strcmp ( const char * str1, const char * str2 ); is the declaration for strcmp function in C.
When we call strcmp function in a program, how exactly does the strcmp function get executed if the function body is not present in the header files?
The code that you want to use like
printfis already compiled and stored somewhere. Your final executable is built when the linker links your object code with the standard library.try
gcc -c somefile.cand see what you get.Also try
gcc -voption and learn the output that it gives.Find out what
ldcommand does and you shall get your answer.Also this what I think should help you : All about compilation/linking/related
UPDATE :
Also Imagine if you defined
printffor every program instdio.hand you includedstdio.hprogram.c :
gcc program.c -o output
So here all your definitions that are there in
stdio.hwould be replaced in theprogram.cfile and your executableoutputwill become pretty HUGE. Instead It would be a better idea to call functions that you use frequently likeprintfinstdio.hfrom one place whenever they are needed