
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
How to write your own header file in C?
Here we will see how to create own header file using C. To make a header file, we have to create one file with a name, and extension should be (*.h). In that function there will be no main() function. In that file, we can put some variables, some functions etc.
To use that header file, it should be present at the same directory, where the program is located. Now using #include we have to put the header file name. The name will be inside double quotes. Include syntax will be look like this.
#include”header_file.h”
Let us see one program to get the idea.
Example
int MY_VAR = 10; int add(int x, int y){ return x + y; } int sub(int x, int y){ return x - y; } int mul(int x, int y){ return x * y; } int negate(int x){ return -x; }
Example
#include <stdio.h> #include "my_header.h" main(void) { printf("The value of My_VAR: %d\n", MY_VAR); printf("The value of (50 + 84): %d\n", add(50, 84)); printf("The value of (65 - 23): %d\n", sub(65, 23)); printf("The value of (3 * 15): %d\n", mul(3, 15)); printf("The negative of 15: %d\n", negate(15)); }
Output
The value of My_VAR: 10 The value of (50 + 84): 134 The value of (65 - 23): 42 The value of (3 * 15): 45 The negative of 15: -15
- Related Articles
- How to write my own header file in C?
- Write your own memcpy() in C
- Write your own atoi() in C++
- Write your own memcpy() and memmove() in C++
- How to write your own LaTeX preamble in Matplotlib?
- Write your own strcmp that ignores cases in C++
- clocale header file in C++
- How will implement Your Own sizeof in C
- Implement your own itoa() in C
- What is an Ansible Playbook and How to Write one on Your Own
- How to Create Your Own Package in Golang?
- How to create your own helper class in Java?
- How to build your own Sqlite database in Python
- How can we write JSON objects to a file in Java?\n
- Print “Hello World” without using any header file in C

Advertisements