Hardey Pandya Hardey Pandya - 1 year ago 69
C Question

What exactly is a "Predefined Function"?

My textbook writes the definition of predefined function as follows :

Predefined means that it is a function that has already been written and compiled, and linked together with our program at the time of linking.

I just can't understand what does it mean. Can you explain ? I actually a beginner in C. I've searched the terminology of compiling and linking. But this definition does not makes sense to me.
My textbook also writes that
is also a predefined function.

Answer Source

I wouldn't trust that textbook if I were you. On page 5 it says:

C permits different forms of main statement. Following forms are allowed.

  • main()

  • int main()

  • void main()

I'm going to stop right there. void main() has never been allowed in standardized C. Similarly it says:

NOTE: Some authors recommend the inclusion of the statement

#include <stdio.h>

at the beginning of all programs that use any input/output library functions. However, this is not necessary for the functions printf and scanf which have been defined as a part of the C language.

It is very bad practice to rely on the implicit definitions of printf (or any library function for that matter.)

Which leads me to believe the authors use of "defined" is shaky at best, since "definition" and "predefined" are words that have exact meanings in the C specification.

A generous interpretation would be that the library functions are linked in via the C library either provided by the compiler or found on your system, which is usually glibc. You can always run ldd on a linux system to see which dynamic library is used for your program.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download