Difference between header files “stdio.h” and “stdlib.h” in C
These are two important header files used in C programming. "<stdio.h>" is the header file of the standard input and output, and "<stdlib.h>" is the header file of the standard library. A simple way to distinguish these two header files is that "<stdio.h>" contains the declarations of printf() and scanf(), and "<stdlib.h>" contains the declarations of malloc() and free(). In this sense, the main difference between the two header files can be considered, although "<stdio.h>" contains the header information of the "file-related input/output" function, and "<stdlib.h>" contains the header of the "memory" Information distribution/release function.
Wait a minute, you said "<stdio.h>" is for file-related IO but printf() and scanf() don't process files... or do they? As a basic principle, in C (because it is related to UNIX history), basic principle, in C (because it is related to UNIX history), the keyboard and display are also considered "files"! In fact, keyboard input is the default standard input file stream, and display output is the default standard output file stream. In addition, please note that although "<stdlib.h>" also contains declarations of other types of functions that are not related to memory, such as atoi(), exit(), rand(), etc., for our purpose and simplicity, we Remember that malloc() and free() are used for "<stdlib.h>"
It should be noted that a header file can contain not only function declaration but definition of constants and variables as well. Even macros and definition of new data types can also be added in a header file.
Comments
Post a Comment