1,228 views

3 Answers

Best answer
4 4 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 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..

Position:
Show:

Related questions

3 3 votes
1 answers 1 answer
852
852 views
junaid ahmad asked Oct 31, 2017
852 views
OUTPUT OF THE FOLLOWING PROGRAMME#include<stdio.h int main() { int n1=10; int n2=15; int n3; n3=~n1; printf("%d",n3); return 0; }Basically here i want to understand how d...
1 1 vote
1 1 answer
1.6k
1.6k views
Vasu Srivastava asked Aug 18, 2017
1,575 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 2 votes
6 answers 6 answers
2.3k
2.3k views
Nitesh Choudhary asked Jun 21, 2017
2,262 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 2 votes
1 1 answer
794
794 views
Sugumaran asked Feb 7, 2018
794 views
#include<stdio.h int main() { int x=191; char *p; p=(char*)&x; printf("%d",*p); }explain it