Movatterモバイル変換


[0]ホーム

URL:


C Custom Header File

C Programming Tutorials

Overview of C LanguageC Language FundamentalsData Input and OutputDecision Control StatementsLoop Control StatementsFunctionsPreprocessors and Header FilesArrays and StringsPointersStructure and UnionFile Handling

You can create yourcustom header file in C; It helps you to manage user-defined methods, global variables, and structures in a separate file, which you can use in different modules.

A Process to Create Custom Header File in C

For example, in the following code, I am calling an external function namedswap in mymain.c file.

Example:

#include<stdio.h>#include"swap.h"void main(){    int a=20;    int b=30;    swap (&a,&b);    printf ("a=%d\n", a);    printf ("b=%d\n",b);}

The swap method is defined in theswap.h file is used to swap two numbers using a temporary variable.

Example:

void swap (int* a, int* b){    int tmp;    tmp = *a;    *a = *b;    *b = tmp;}
  • The header file name must have a.h file extension.
  • In this example, I have namedswap.h header file.
  • Instead of writing<swap.h> use this terminologyswap.h to include a custom header file.
  • Both filesswap.h andmain.c must be in the same folder.


Found This Page Useful? Share It!
Get the Latest Tutorials and Updates
Join us on Telegram

[8]ページ先頭

©2009-2025 Movatter.jp