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 🙂
- Difference between Header file and Library
- Comment in header file name?
- clocale header file in C++
- How to write your own header file in C?
- accumulate() and partial_sum() in C++ STL : numeric header
- time.h header file in C with Examples
- Print "Hello World" in C/C++ without using any header file
- numeric header in C++ STL | Set 2 (adjacent_difference(), inner_product() and iota())
- Namespace in C++ | Set 3 (Accessing, creating header, nesting and aliasing)
- Linking Files having same variables with different data types in C
- C Program to list all files and sub-directories in a directory
- C Program to merge contents of two files into a third file
- C program to compare two files and report mismatches
- Difference between Tor and VPN
- Difference between USB 2.0 and USB 3.0