- 2069 Chaitra · 2 marks
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)
Related questions
- Correct program: do-while and pow · Computer Programming, chapter 3
- Correct program: Celsius to Fahrenheit · Computer Programming, chapter 3
- Output of arithmetic expression program · Computer Programming, chapter 3
- Correct program: character arrays · Computer Programming, chapter 7
- Need of analysis and design · Computer Programming, chapter 2
- Copy contents of one file to another · Computer Programming, chapter 10 · asked 2×
- Why do we need DFT · Digital Signal Analysis and Processing, chapter 7 · asked 6×
- Why do we need FFT · Digital Signal Analysis and Processing, chapter 7 · asked 2×
- File stream; student binary file program · Object Oriented Programming, chapter 8
- File size: 20 s, 44.1 KHz, 8-bit stereo · Multimedia System, chapter 2 · asked 2×