Skip to main content

Need of stdio.h header file

Short answer

<stdio.h> contains function prototypes and macros for standard I/O like printf and scanf. Without it, the compiler may warn or error. A C program can work without any header if it uses no library functions, or if we declare the needed prototype manually.

Why do we include <stdio.h> in our program? Can we write a C program without using any header file?

We include <stdio.h> (standard input/output header) because it contains the declarations (prototypes) of the standard I/O functions such as printf(), scanf(), getchar(), putchar(), gets() and the file functions, as well as macros such as NULL and EOF. Without it the compiler does not know these functions and gives an error or warning.

Can we write a C program without any header file? Yes, if the program does not use any library function. For example:

int main(void)
{
    int a = 2, b = 3;
    return a + b;     /* no library function used, so no header needed */
}

This compiles and runs; it just returns 5 to the operating system. It is also possible to use printf without the header by declaring its prototype ourselves:

int printf(const char *format, ...);   /* declare printf ourselves */
int main(void)
{
    printf("Works without stdio.h\n");
    return 0;
}

Output:

Works without stdio.h

In practice, headers are included so that functions are declared correctly.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Programming chapter 3 questions →