Can users create their own custom header files in C language? If so, how can I access user-defined header files?
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 -
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); }
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; }
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!