How to Create your own Header file in C

[207 views]


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!

        

Algorithm Logic Test

Our Quiz prepared by Experts Helps you identify your knowledge in Algorithms. Everyone should atleast attempt this Quiz Once. 



Comments



Recommended Book Deals Ends in

Download 101 Ready to Use Excel Formulas ebook
Download Python All in One for Dummies ebook



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

Search Tags

    Create Header File in C programming language