how to create our own header files
Hello friends I am here with my post which is how to create
your own header files but before start I would like to explain what a header
file is and why it is used in our program.
We all know that a program contain different library
functions to perform the given job by user. A header file contains the definition
of the functions which is included in that header file. Definition of a
function tells the compiler that what operation that function have to perform or
in what manner and how many number of argument it accept and how many argument
it will return .the type of arguments everything about that function. There are
number of header files used in c programming we just have to call as per as our
requirement .header files are very useful so let’s make a header file of our
own.
Follow these steps:
First of all create the definition of a function and save it
with the extension .h (my_func.h)
Example:
int sum(int a,int b)
{
return(a+b);
}
·
Now create a program for adding two numbers and
include it with directive #include<my_func.h>
·
And create the program and call the function which
you have made
Example:
#include<my_func.h>
Void main()
{
int i,j,s;
Printf(“enter two numbers”);
Scanf(“%d%d”,&i,&j);
s=sum(i,j);
printf(“The sum of given number is =%d”,s);
}
Comments
Post a Comment