Header Files in C
Header Files in C
#include<file>
#include "file"
There is a difference between the header files given above. If the header file is
defined within the predefined source path, we can specify the header within the
angular brackets. If the header file is not defined within the predefined source
path then we can specify the full path of the header file within the double-quotes.
Header Files in C 1
• First, we will write our own C code and save the file with .h extension. Below is
the example to create our header file:
#include<stdio.h>
// including header file
#include "multiply.h"
int main()
{
int a =1, b = 2; // definition of two numbers
// function defined in multiply.h header file to calculate
printf("Result of multiplication is : %d",multiply(a, b))
return 0;
}
Header Files in C 2
Header Files in C 3
Header Files in C 4
Header Files in C 5
Example 1:
// C program to understand the usage of header file.
#include <stdio.h>
#include <string.h>
#include <math.h>
int main()
{
char str1[10] = "hello";
char str2[10] = "javatpoint";
Header Files in C 6
// function defined in math.h header file
long int a = pow(3, 3);
printf("The value of a is %d", a);
// function defined in string.h to calculate the length of t
int length = strlen(str2);
printf("\nThe length of the string str2 is : %d", length);
return 0;
}
Header Files in C 7
Example: Program to get the ASCII value of the capital
letters
#include <stdio.h>
int main()
{
// declare local variable
int caps;
// use for loop to print the capital letter from A to Z
for ( caps = 65; caps < 91; caps++)
{
printf (" \n The ASCII value of %c is %d ", caps, caps);
Header Files in C 8
}
return 0;
}
Header Files in C 9