How to Create your own Header file in C


In order to create your own header file, we create a function and save it with .h extension. This file contains only function and nothing else.

In the Main file which you have to save as .c extension and where you want that function to work. We will write a line #include"filename.h" use the function same as it is declared in the same file.

create your own header file in C

Main Program (Save with .c extension):

#include<stdio.h> #include"factorial.h" int main() { int n, ans; printf("Enter a number to find it's factorial:"); scanf("%d", & n); ans = fact(n); printf("%d", ans); }

Header File (Save as factorial.h)

int fact(int a) { if (a == 1) return 1; else return a * fact(a - 1); }

That's it! You have learnt how to create your own header file and how to use.

Happy Coding!


Struggling to Understand Algorithm and Flowchart? Try our Notes

Want to Test Your Knowledge on Algorithm and Flowchart?


Recommended Deals End in

Online Games
Play 2048 Game Online and Relax.
Play 2048 Game Online

Search Tags

    Create Header File in C programming language