- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What happens if we include header file for two times in a C program?
C header files include some predefined functions. For example, printf() and scanf() functions are defined in the stdio.h header file.
Each header files in C contains different predefined functions to make programs simple to understand.
When a header file is included two times in a C program, the second one gets ignored. In actual, the #, called the include, preceding a header file ensures that it is included only once during the compilation process.
Example 1
Following is the C program for computing an average of three numbers −
#include<stdio.h> #include<stdio.h> //header file included twice ,ignored by compiler main(){ int a,b,c,d; float avg; printf("Enter values for a,b,c:"); scanf("%d%d%d",&a,&b,&c); d=a+b+c; avg=d/3; printf("Average avg=%f",avg); }
Output
When the above program is executed, it produces the following result −
Enter values for a,b,c:3 3 3 Average avg=3.000000
Example 2
Consider another C program for header files −
#include<stdio.h> #include<stdio.h> #include<stdlib.h> #include<stdlib.h> //header file included twice ,ignored by compiler main(){ int a,b,c; printf("Enter values for a,b:"); scanf("%d%d",&a,&b); c=a+b; printf("sum=%d",c); }
Output
When the above program is executed, it produces the following result −
Enter values for a,b:2 4 sum=6
- Related Articles
- Include a header for a document or section in HTML5?
- clocale header file in C++
- What happens if we eat two bananas on an empty stomach?
- What happens if we re-declare a variable in JavaScript?
- What happens if I will add a UNIQUE constraint on the same column for multiple times?
- What happens if we grow kharif crops in winter?
- What is overloading? What happens if we overload a main method in java?
- What happens if we try to extend a final class in java?
- What happens if we define a concrete method in an interface in java?
- How to write my own header file in C?
- How to write your own header file in C?
- How do I include a php.ini file in another php.ini file?
- Print “Hello World” without using any header file in C
- What happen if we concatenate two string literals in C++?
- What happens if an exception is not handled in a java program?

Advertisements