Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

is header file must in c programming?

+19 votes
asked Mar 29 by Sai kiran Mamidi (220 points)

7 Answers

0 votes
answered Mar 30 by sk1a345 (140 points)
Yes if you want that your code should run efficiently without giving any error then it is required to include header files. For example #include<stdio.h> this header file contains the meaning of the predefined functions like printf() and scanf() in c. unless and untill you are not adding this header file you cannot use the predefined functions in your code.
0 votes
answered Mar 30 by Mayur Gaikwad (250 points)
It is possible to write code not using is header files but using header files is more reliable  than not using.
0 votes
answered Mar 31 by Kritika (140 points)
yes header file is must in c programming
0 votes
answered Apr 1 by Alex (140 points)
Depends on what you mean.

If you mean needing to link a header file, technically no but you probably wouldn't. For starters, without any includes you need to be proficient in your systems assembly to log anything into the terminal.

If you mean needing to make your header files, while it is not something you are forced to do, it is a good idea if you are making a somewhat large project where putting everything into one file may not be very practical.
+1 vote
answered Apr 1 by Peter Minarik (88,130 points)
edited Apr 16 by Peter Minarik

No, it's not. However, they exist for convenience and to help deal with larger projects so code wouldn't need to be copied over and over.

You can include header files provided by others, e.g. <stdio.h> for standard input/output operations, and you can also make your own header files if you want to share types across multiple files or you'd like to offer functionality for 3rd parties (e.g. you're creating an API).

It is highly recommended to create header files for anything more than a single file project.


I've seen some people saying you need stdio.h or other headers. This is not true. They exist for your convenience, but you do not absolutely need to use them. You can just pick the function declarations from those headers that you would actually use in your code. They work because the header file contains just the declarations, but the definitions live somewhere else and they will be linked against your compiled project automatically (at least the standard library functions).

Here's an illustration below. Enjoy!

extern int printf(const char * format, ...);
extern int scanf(const char * format, ...);

int main()
    printf("Did you know you do not absoutely need to include stdio.h?\n");
    printf("Isn't this amazing?!");

    return 0;
0 votes
answered Apr 10 by 19G01A0488 Saikiran (140 points)
printf and scanf functions are there in  header files only i you want to use them you have to include header file
0 votes
answered May 6 by ib G (210 points)

No, header files are not strictly necessary in C programming, but they are a common and convenient way to organize code. Header files typically contain declarations of functions, variables, constants, and other elements that are shared across multiple source files in a C project. By including a header file at the beginning of a source file using the `#include` preprocessor directive, you can make the declarations in the header file available for use in that source file.

Header files help in modularizing code and promoting code reuse by separating interface declarations from implementation details. While you can declare functions and variables directly in your source files without using header files, doing so can lead to code duplication and maintenance issues, especially in larger projects. So while header files are not mandatory, they are a best practice in C programming.

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.