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:
What’s difference between header files "stdio.h" and "stdlib.h" ?
Next article icon

Header Files in C

Last Updated : 16 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

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 libraries and their components for use in programs.

Example:

C
// Adding standard input and output library by // including stdio.h header file #include <stdio.h>  int main() {      	// printf() function from stdio.h header file     printf("Hello");     return 0; } 

Output
Hello

In the above program, we have included the stdio.h header file that provides the standard input and output library in C.

Include Header Files

We have to include header files in our C program to use its features. There are two ways to do that:

C
// for header files in system/default // directory #include <filename.h>     // for Header files in same directory as // source file #include "filename.h"    

The #include preprocessor directs the compiler that the header file needs to be processed before compilation and includes all the necessary data types and function definitions.

header files in C
C Header File

Types of C Header Files

There are two types of header files in C:

  1. Standard / Pre-existing header files
  2. Non-standard / User-defined header files

Standard Header Files in C

Standard header files contain the libraries defined in the ISO standard of the C programming language. They are stored in the system directory of the compiler and are present in all the C compilers from any vendor.

There are 31 standard header files in the latest version of C language. Following is the list of some commonly used header files in C:

Header File

Description

<assert.h>It contains information for adding diagnostics that aid program debugging.
<errno.h>It is used to perform error handling operations like errno(), strerror(), perror(), etc.
<float.h>

It contains a set of various platform-dependent constants related to floating point values. These constants are proposed by ANSI C. 

They make programs more portable. Some examples of constants included in this header file are- e(exponent), b(base/radix), etc.

<math.h>It is used to perform mathematical operations like sqrt(), log2(), pow(), etc.
<signal.h>It is used to perform signal handling functions like signal() and raise().
<stdarg.h>

It is used to perform standard argument functions like va_start() and va_arg(). It is also used to indicate start of the

variable-length argument list and to fetch the arguments from the variable-length argument list in the program respectively.

<ctype.h>

It contains function prototypes for functions that test characters for certain properties, and also function prototypes for 

functions that can be used to convert uppercase letters to lowercase letters and vice versa.
 

<stdio.h>It is used to perform input and output operations using functions like scanf(), printf(), etc.
<setjump.h>

It contains standard utility functions like malloc(), realloc(), etc. It contains function prototypes for functions that allow bypassing 

of the usual function call and return sequence.

<string.h>It is used to perform various functionalities related to string manipulation like strlen(), strcmp(), strcpy(), size(), etc.
<limits.h>

It determines the various properties of the various variable types. The macros defined in this header limits the values of 

various variable types like char, int, and long. These limits specify that a variable cannot store any value 

beyond these limits, for example, an unsigned character can store up to a maximum value of 255.

<time.h>

It is used to perform functions related to date() and time() like setdate() and getdate(). It is also used to modify the system date 

and get the CPU time respectively.

<stddef.h>It contains common type definitions used by C for performing calculations.
<locale.h>

It contains function prototypes and other information that enables a program to be modified for the current locale on which it’s running. 

It enables the computer system to handle different conventions for expressing data such as times, dates, or large numbers throughout the world.

Example

The below example demonstrates the use of some commonly used header files in C.

C
#include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h>  int main(){     char s1[20] = "12345";     char s2[10] = "Geeks";     char s3[10] = "ForGeeks";     long int res;      // Find the value of 9^3 using a     // function in math.h library     res = pow(9, 3);     printf("Using math.h, "            "The value is: %ld\n",            res);      // Convert a string to long long int     // using a function in stdlib.h library     long int a = atol(s1);     printf("Using stdlib.h, the string");     printf(" to long int: %ld\n", a);      // Copy the string s3 into s2 using     // using a function in string.h library     strcpy(s2, s3);     printf("Using string.h, the strings"            " s2 and s3: %s %s\n",            s2, s3);     return 0; } 

Output
Using math.h, The value is: 729 Using stdlib.h, the string to long int: 12345 Using string.h, the strings s2 and s3: ForGeeks ForGeeks

Non-Standard Header Files

Non-standard header files are not part of the language's ISO standard. They are generally all the header files defined by the programmers for purposes like containing custom library functions etc or provided as external libraries by different vendors. They are manually installed by the user or maybe part of the compiler by some specific vendor.

There are lots of non-standard libraries for C language. Some commonly used non-standard/user-defined header files are listed below:

Header FileDescription
<conio.h>It contains some useful console functions.
<gtk/gtk.h>It contains GNU's GUI library for C.

Example

The below example demonstrates the use of conio.h non-standard header file.

C
#include<stdio.h> #include<conio.h>  // Function to display a welcome message void displayMessage() {     printf("Hello! Geek\n"); } int main() {        // Using conio.h functions     printf("Press any key to print message \n");        // Wait for a key press     getch();       // Call the additional function after a key press     displayMessage();      return 0; } 


Output

Press any key to print message 
Hello! Geek

Create your own Header File in C

Instead of writing a large and complex code again and again in different programs, we can create our own header files and include them in our program to use whenever we want. It enhances code functionality and readability. These header files are generally kept inside the source file directory and included using the second syntax to include header files, but we can also install them in the compilers default directory.

Refer to this article to know more - How Do I Create a Library in C?


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

M

meghaabishtt
Improve
Article Tags :
  • C Language
  • C Basics
  • C-Library

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