What does '#include <stdio.h>' really do in a C program

It looks for the stdio.h file and effectively copy-pastes it in the place of this #include statements. This file contains so-called function prototypes of functions such as printf(), scanf(), ... so that compiler knows what are their parameters and return values.


The simplest explanation perhaps should be that your program calls or uses many functions whose code is not part of your program itself. For e.g. if you write "printf" in your code to print something, the compiler does not know what to do with that call.

stdio.h is the place where information for that printf resides.

Update:

Rather the prototype of printf function (name, return type and parameters) reside in stdio.h. That is all required in the compilation phase. The actual code of printf is included in the linking phase, which comes after compilation.

The include statement basically inserts all function prototypes BEFORE the actual compilation. Hence the name preprocessor.

Update 2:

Since the question focused on include statement (and the OP also asked about writing definition of functions himself, another important aspect is if it is written like (note the angular brackets)

#include <stdio.h>

The preprocessor assumes, it is a standard library header and looks in the system folders first where the compiler has been installed.

If instead a programmer defines a function by himself and place the .h file in the current working directory, he would use (note the double quotes)

#include "stdio.h"

Following illustrates it and the behavior is portable across all platforms.


Preprocessor directives in a source code are the statements which are processed before the compilation of a program, after this step the source code is converted into the expanded source code as it now contains the references to the functions which are already defined in the Standard C Library(or any other) like printf, scanf, putw, getchar etc. The stdio.h is a file with ".h" extension that contains the prototypes (not definition) of standard input-output functions used in c.


It tells the compiler to use functions, structures, macros and etc from file sdtio.h, which represents a part of glibc(or whatever is the standart C library you got). Compiler also adds record to the output executable "to-link list", that it should be linked to standart C library.

Tags:

C

Include

Stdio