How to write my own header file in C?



Steps to write my own header file in C −

  • Type a code and save it as “sub.h”.
  • Write a main program “subtraction.c” in which −
    • include new header file.
    • Write “sub.h” instead of <sub.h>
    • All the functions in sub.h header are now ready for use.
    • Directly call the function sub().
    • Both “subtraction.c” and “sub.h” should be in same folder.

Sub.h

int sub(int m,int n) {    return(m-n); }

subtraction.c

Example

#include<stdio.h> #include "sub.h" void main() {    int a= 7, b= 6, res;    res = sub(a, b);    printf("Subtraction of two numbers is: %d", res); }

After running ”subtraction.c” the output will be −

Output

Subtraction of two numbers is: 1
Updated on: 2019-07-30T22:30:26+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements