C/printf
Expert: Narendra - 6/20/2006
Question Hello narendra,
printf is a function. so where its definition is stored. what is the need of header file..
AnswerI think, yesterday itself I answered this question and I think you only asked this!
Anyway, I will answer this again:
1. printf is a function. so where its definition is stored?
It's definition is in a library called libc.so
This library gets linked to any program that you compile.
Compiler itself picks up some standard libraries and hence you won't see its linking in the command.
2. what is the need of header file..?
Header file contains the declaration.
If you know the difference between definition and declaration, then you will understand this.
For your compiler to compile your code, it needs to know any variable or function name before it gets used.
Otherwise it gives errors.
The reason is, without knowing the type of the variable or function prototype, it will not be able to does further processing. For this it needs to know these info.
Now, you use your printf() and many similar functions thru out your program and you haven't defined them.
The definition is in a library and that comes into picture only during linking! So, how to know the prototype of printf() function.
This is done with the help of header files.