These are two important header files used in C programming. While “<stdio.h>” is header file for Standard Input Output, “<stdlib.h>” is header file for Standard Library. One easy way to differentiate these two header files is that “<stdio.h>” contains declaration of printf() and scanf() while “<stdlib.h>” contains declaration of malloc() and free(). In that sense, the main difference in these two header files can considered that, while “<stdio.h>” contains header information for ‘File related Input/Output’ functions, “<stdlib.h>” contains header information for ‘Memory Allocation/Freeing’ functions.
Wait a minute, you said “<stdio.h>” is for file related IO but printf() and scanf() don’t deal with files… or are they? As a basic principle, in C (due to its association with UNIX history), keyboard and display are also treated as ‘files’! In fact keyboard input is the default stdin file stream while display output is the default stdout file stream. Also, please note that, though “<stdlib.h>” contains declaration of other types of functions as well that aren’t related to memory such as atoi(), exit(), rand() etc. yet for our purpose and simplicity, we can remember malloc() and free() 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.
Please do Like/Tweet/G+1 if you find the above useful. Also, please do leave us comment for further clarification or info. We would love to help and learn 🙂
- How to print a variable name in C?
- What’s difference between HTML and HTTP ?
- A C Programming Language Puzzle
- Diffference between #define and const in C?
- Arrays in C/C++
- What’s difference between Priority Inversion and Priority Inheritance ?
- Do not use sizeof for array parameters
- Constants in C
- Interesting Facts about Macros and Preprocessors in C
- Commonly Asked C Programming Interview Questions | Set 1
- What’s difference between char s and char *s in C?
- Pointers in C and C++ | Set 1 (Introduction, Arithmetic and Array)
- gets() is risky to use!
- The OFFSETOF() macro
- Data type of case labels of switch statement in C++?