621 views

3 Answers

Best answer
3 votes
3 votes

Edit: It depends on contents of the header file.

Header files are literally copied and pasted into the body of your C files

So may be it will give an error if the same function is there twice. 

In compiler like GCC

If a header file happens to be included twice, the compiler will process its contents twice. This is very likely to cause an error, e.g. when the compiler sees the same structure definition twice. Even if it does not, it will certainly waste time.

Source: https://gcc.gnu.org/onlinedocs/gcc-3.0.2/cpp_2.html

So the answer is "Yes" though not for all header files.

selected by
4 votes
4 votes

Header file is nothing but the file which contains the declarations(or prototypes) of the functions which we use in our code..For example  , for using input - output functions , we need "stdio.h" header file..

For string manipulation functions , like strlen() we need "string.h" header file..So including a header twice will have no problem ; just a redundancy as the function in main() will get its prototype from any one of the include statement..

Hence it should not give an error..

Related questions

3 votes
3 votes
1 answer
1
1 votes
1 votes
1 answer
2
Vasu Srivastava asked Aug 18, 2017
1,047 views
#include <stdio.h int main(void){ int i=511; char *p = (char *)&i; printf("%d", *p); }OK so why take 2's complement and not simple binary number? Means, why is C giving -...
2 votes
2 votes
6 answers
3
Nitesh Choudhary asked Jun 21, 2017
1,130 views
what is the o/p #include<stdio.h void main() { int a=5; printf("%d %d %d",a++,++a, a); }also suggest me notes so i can clear my concept about printf function (For Gate)
2 votes
2 votes
1 answer
4
Sugumaran asked Feb 7, 2018
491 views
#include<stdio.h int main() { int x=191; char *p; p=(char*)&x; printf("%d",*p); }explain it