Home > Backend Development > C++ > body text

Explain custom header files in C language

PHPz
Release: 2023-09-06 08:57:21
forward
1068 people have browsed it

Explain custom header files in C language

Question

Can users create their own custom header files in C language? If so, how can I access user-defined header files?

Solution

Yes, users can create their own custom header files in C.

It helps you manage user-defined methods, global variables and structures in a separate file that can be used in different modules.

Let us see an example of how to create and access a custom header file -

Example

Given below is a call to an external function swap in the main file main.c C program.

#include<stdio.h>
#include"swaping.h" //included custom header file
void main(){
   int a=40;
   int b=60;
   swaping (&a,&b);
   printf ("a=%d</p><p>", a);
   printf ("b=%d</p><p>",b);
}
Copy after login

The swapping method is defined in the swapping.h file and is used to swap two number.

This code is saved in the same folder as the main.h file by using swapping.h. h has been saved.

void swapping (int* a, int* b){
   int temp;
   temp = *a;
   *a = *b;
   *b = temp;
}
Copy after login

Note

  • The extension of the header file is .h.

  • The files swapping.h and main.c must be in the same folder.

  • To distinguish between predefined and custom header files, we use #include "swapping.h" instead of .

The above is the detailed content of Explain custom header files 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