Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • C
  • C Basics
  • C Data Types
  • C Operators
  • C Input and Output
  • C Control Flow
  • C Functions
  • C Arrays
  • C Strings
  • C Pointers
  • C Preprocessors
  • C File Handling
  • C Programs
  • C Cheatsheet
  • C Interview Questions
  • C MCQ
  • C++
Open In App
Next Article:
How to write your own header file in C?
Next article icon

What’s difference between header files "stdio.h" and "stdlib.h" ?

Last Updated : 02 Jan, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

In C programming, standard header files provide various inbuilt functionalities and two of the most commonly used standard header files are stdio.h and stdlib.h. The <stdio.h> provides Standard Input Output tools such as printf(), scanf(), etc while <stdlib.h> provides some commonly used utility tools malloc(), calloc(), etc.

The primary differences between these two header files are listed in the below table:

Aspect

stdio.h

stdlib.h

Purpose

Focuses on input and output operations (reading and writing to console and files).Provides functions for memory allocation, process control, random number generation, and conversion between data types.

Functions Provided

Includes functions like printf(), scanf(), getchar(), and file I/O functions.Includes functions like malloc(), free(), exit(), atoi(), and rand().

Scope

Primarily deals with handling input and output.Deals with system-level utilities, memory management, and other miscellaneous operations.

Usage

stdio.h is used by almost every C program.stdlib.h is only use when we need to allocate memory in our program.

What is stdio.h?

The stdio.h header file stands for Standard Input Output and provides functions for input and output operations. It includes functions to perform tasks like reading from and writing to the console, handling files, and managing formatted input/output.

Functions provided by stdio.h:

CategoryFunctionDescription
Console I/Oprintf()Prints formatted output to the standard output (console).
scanf()Reads formatted input from the standard input (console).
putchar()Writes a single character to the standard output (console).
getchar()Reads a single character from the standard input (console).
puts()Writes a string followed by a newline to the standard output (console).
gets()Reads a string from the standard input (deprecated due to lack of safety).
File Handlingfopen()Opens a file.
fclose()Closes a file.
fread()Reads data from a file.
fwrite()Writes data to a file.
fseek()Moves the file pointer to a specific position in a file.
ftell()Returns the current position of the file pointer.
rewind()Resets the file pointer to the beginning of the file.
fprintf()Writes formatted output to a file.
fscanf()Reads formatted input from a file.
fgetc()Reads a single character from a file.
fputc()Writes a single character to a file.
fgets()Reads a line of text from a file.
fputs()Writes a string to a file.
feof()Checks if the end-of-file indicator is set for a file.
ferror()Checks for a file error.
Temporary Filestmpfile()Creates a temporary file that is automatically deleted when closed.
tmpnam()Generates a unique temporary file name.
Buffer Managementsetbuf()Sets the buffer for a file stream.
setvbuf()Sets the buffer and mode for a file stream.
Error Handlingperror()Prints an error message describing the last error.
clearerr()Clears the error and end-of-file indicators for a file.

What is stdlib.h?

The stdlib.h header file stands for Standard Library and provides functions for memory allocation, process control, conversions, and other utilities that are not related to input/output. It contains functions for dynamically allocating memory, generating random numbers, and controlling program execution.

Functions provided by stdlib.h:

CategoryFunctionDescription
Memory Managementmalloc()Allocates a block of memory.
calloc()Allocates and initializes a block of memory.
realloc()Resizes a previously allocated block of memory.
free()Deallocates previously allocated memory.
Random Number Generationrand()Generates a pseudo-random number.
srand()Seeds the random number generator with a specific value.
Process Controlexit()Terminates the program immediately.
abort()Abnormally terminates the program.
atexit()Registers a function to be executed upon program termination.
system()Executes a system command.
Type Conversionatoi()Converts a string to an integer.
atol()Converts a string to a long integer.
atof()Converts a string to a floating-point number.
strtol()Converts a string to a long integer with error checking.
strtoll()Converts a string to a long long integer with error checking.
strtoul()Converts a string to an unsigned long integer with error checking.
strtoull()Converts a string to an unsigned long long integer with error checking.
strtod()Converts a string to a double with error checking.
strtof()Converts a string to a float with error checking.
strtold()Converts a string to a long double with error checking.
Searching and Sortingqsort()Performs a quick sort on an array.
bsearch()Performs a binary search in a sorted array.
Mathematical Utilitiesabs()Returns the absolute value of an integer.
labs()Returns the absolute value of a long integer.
llabs()Returns the absolute value of a long long integer.
div()Computes quotient and remainder of integer division.
ldiv()Computes quotient and remainder of long integer division.
lldiv()Computes quotient and remainder of long long integer division.
Environment Handlinggetenv()Retrieves the value of an environment variable.
putenv()Adds or changes an environment variable.
setenv()Sets a new environment variable.
unsetenv()Removes an environment variable.
Multibyte and Wide-Character Conversionmblen()Returns the number of bytes in the next multibyte character.
mbstowcs()Converts a multibyte string to a wide-character string.
mbtowc()Converts a multibyte character to a wide character.
wcstombs()Converts a wide-character string to a multibyte string.
wctomb()Converts a wide character to a multibyte character.
Dynamic Allocation for Arrayaligned_alloc()Allocates memory with a specified alignment.

Conclusion

In summary, stdio.h and stdlib.h are both essential header files in C programming but serve different purposes. stdio.h is focused on input/output operations, including console and file handling, while stdlib.h is used for system-level tasks like memory management, program control, and number conversion. Understanding when and how to use these header files will significantly improve your C programming skills.


Next Article
How to write your own header file in C?

K

kartik
Improve
Article Tags :
  • Difference Between
  • Articles
  • C Language
  • CPP-Library
  • C-Macro & Preprocessor

Similar Reads

    C Preprocessors
    Preprocessors are programs that process the source code before the actual compilation begins. They are not part of the compilation process but operate separately, allowing programmers to modify the code before compilation. It is the first step that the C source code goes through when being converted
    8 min read
    C Preprocessor Directives
    In C programming, the preprocessor is a program that process the source code before the actual compilation begins. It uses preprocessor directives are commands that instruct the preprocessor to perform specific actions. These directives start with the # symbol.List of Preprocessor DirectivesThe foll
    6 min read
    How a Preprocessor works in C?
    Compiling a C program - Behind the Scene A Preprocessor is a system software (a computer program that is designed to run on computer's hardware and application programs). It performs preprocessing of the High Level Language(HLL). Preprocessing is the first step of the language processing system. Lan
    3 min read
    Header Files in C
    In C programming, a header file is a file that ends with the .h extension and contains features like functions, data types, macros, etc that can be used by any other C program by including that particular header file using "#include" preprocessor.C language uses header files to provide the standard
    5 min read
    What’s difference between header files "stdio.h" and "stdlib.h" ?
    In C programming, standard header files provide various inbuilt functionalities and two of the most commonly used standard header files are stdio.h and stdlib.h. The <stdio.h> provides Standard Input Output tools such as printf(), scanf(), etc while <stdlib.h> provides some commonly used
    4 min read
    How to write your own header file in C?
    As we all know that files with .h extension are called header files in C. These header files generally contain function declarations which we can be used in our main C program, like for e.g. there is need to include stdio.h in our C program to use function printf() in the program. So the question ar
    4 min read
    Macros and its types in C
    In C programming, a macro is a symbolic name or constant that represents a value, expression, or code snippet. They are defined using the #define directive, and when encountered, the preprocessor substitutes it with its defined content.ExampleC#include <stdio.h> // Macro definition #define LIM
    4 min read
    Interesting Facts about Macros and Preprocessors in C
    In a C program, all lines that start with # are processed by preprocessor which is a special program invoked by the compiler. by this we mean to say that the ‘#’ symbol is used to process the functionality prior than other statements in the program, that is, which means it processes some code before
    5 min read
    # and ## Operators in C
    In C, # and ## operators are preprocessor operators using in macros for token manipulation. They are known as stringizing and token pasting operators and are used in macro definition with #define preprocessor. In this article, we will learn about these operators and how to use them in C programs.Str
    3 min read
    How to print a variable name in C?
    Printing a variable name means printing the identifier that is assigned to the variable. To print it, it should be in the form of string. This can be done by using stringification.Stringification in C is the method to convert the argument of a function like macro to a string. This can be done with t
    1 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences