Home > Backend Development > C++ > How to write your own header file in C language?

How to write your own header file in C language?

PHPz
Release: 2023-09-15 14:53:02
forward
2141 people have browsed it

How to write your own header file in C language?

Steps to write your own header file in C −

  • Enter the code and save it as "sub.h".
  • Write a main program named "subtraction.c", which −
    • contains the new header file.
    • Use "sub.h" instead of
    • All functions in the sub.h header file now work.
    • Call function sub() directly.
    • "subtraction.c" and "sub.h" should be in the same folder.

Sub.h

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

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);
}
Copy after login

After running "subtraction.c", the output will output

Subtraction of two numbers is: 1
Copy after login

for −

The above is the detailed content of How to write your own header file in C language?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template