Online visitors

People learning around the world

Online

—

Visitors exploring W3Schools

Online visitors by country Circles show approximate country locations. The country list provides the visitor counts.

Circles represent countries, not exact visitor locations.

Country

Online

Loading country activity…

    C Custom Header File

    You can create your custom 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 named swap in my main.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 the swap.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 named swap.h header file.
    • Instead of writing <swap.h> use this terminology swap.h to include a custom header file.
    • Both files swap.h and main.c must be in the same folder.


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

    Notifications

    Updates are enabled for this browser.

    Receive new tutorials, articles and learning resources. You can turn updates off anytime.