C Program to Create Your Own Header File in C Programming
Step 1: Make a user defined function.
int add(int x,int y)
{return (x+y);}
- write only function definition
Step 2: Save code
- save the above code with extension .h.
- compile if required
Step 3: write main program
#include<stdio.h>
#include"myheader.h"
void main() {
int num1 = 10, num2 = 10, num3;
num3 = add(num1, num2);
printf("Addition of Two numbers : %d", num3);
}
- Include Our New Header File .
- Instead of writing < myheader.h> use this terminology “myheader.h”
- All the Functions defined in the myheader.h header file are now ready for use .
- Directly call function add(); [ Provide proper parameter and take care of return type ]
Note
- While running your program precaution to be taken : Both files [ myheader.h and example.c ] should be in same folder.