C Programming - C Preprocessor - Discussion
Discussion Forum : C Preprocessor - Yes / No Questions (Q.No. 4)
4.
It is necessary that a header files should have a .h extension?
Answer: Option
Explanation:
No, the header files have any kind of extension.
Discussion:
16 comments Page 1 of 2.
Deepak said:
5 years ago
We include files into our source as follows:
In case of files placed in your _include_ dir
which you tell the compiler to look into
#include <filename.ext>
In case of other files, which are not in compiler's known include dir
#include "relative/path/to/filename.ext".
In either case, what the pre-possessor does is pretty simple. It reads the whole content of that file and replaces this line with *the whole content*. That's it. Nothing more, nothing less.
Any extension is fine as long as you keep text data into it which it could "include". Any extension and any text content should work.
Haven't given it a try, but if a binary format file (like an image) is included, the preprocessor will most likely read it as ASCII files and copy it too, and then complain about the grammar.
In case of files placed in your _include_ dir
which you tell the compiler to look into
#include <filename.ext>
In case of other files, which are not in compiler's known include dir
#include "relative/path/to/filename.ext".
In either case, what the pre-possessor does is pretty simple. It reads the whole content of that file and replaces this line with *the whole content*. That's it. Nothing more, nothing less.
Any extension is fine as long as you keep text data into it which it could "include". Any extension and any text content should work.
Haven't given it a try, but if a binary format file (like an image) is included, the preprocessor will most likely read it as ASCII files and copy it too, and then complain about the grammar.
Sundar said:
1 decade ago
@ALL
Is is necessary that a header files should have ".h" ?
Answer is NO.
Because the header files can have any extension but it should be included with in C program with same extension.
Let me explain what I did to check this...
In Turbo C directory
C:\Turbo>copy stdio.h stdio.hdr
C:\Turbo>copy conio.h conio.exe
Then I used the line following line to include the header file.
#include<stdio.hdr>
#include<conio.exe>
void main()
{
printf("Welcome to IndiaBIX.com !");
getch();
}
The output : Welcome to IndiaBIX.com !
Is is necessary that a header files should have ".h" ?
Answer is NO.
Because the header files can have any extension but it should be included with in C program with same extension.
Let me explain what I did to check this...
In Turbo C directory
C:\Turbo>copy stdio.h stdio.hdr
C:\Turbo>copy conio.h conio.exe
Then I used the line following line to include the header file.
#include<stdio.hdr>
#include<conio.exe>
void main()
{
printf("Welcome to IndiaBIX.com !");
getch();
}
The output : Welcome to IndiaBIX.com !
Harish said:
8 years ago
@ALl.
vi hi.q
{
#include<stdio.h>
}
vi prog.c
#include"hi.q"
int main()
{
printf("in prog.c file\n");
}
cc hi.q prog.c
o/p error: file format not recognized
But if we use with hi.h, then it's working properly. so, I think the extension should be .h only.
vi hi.q
{
#include<stdio.h>
}
vi prog.c
#include"hi.q"
int main()
{
printf("in prog.c file\n");
}
cc hi.q prog.c
o/p error: file format not recognized
But if we use with hi.h, then it's working properly. so, I think the extension should be .h only.
Aksahy said:
8 years ago
@Sundar.
It's NOT WORKS IN code blocks.
#include<stdio.hdr>
#include<conio.exe>
void main()
{
printf("Welcome to IndiaBIX.com !");
getch();
}
The output : Welcome to IndiaBIX.com!
It's NOT WORKS IN code blocks.
#include<stdio.hdr>
#include<conio.exe>
void main()
{
printf("Welcome to IndiaBIX.com !");
getch();
}
The output : Welcome to IndiaBIX.com!
Jyoti Nagpal said:
1 decade ago
#include"filename.c".
"this is also a header file".
In a extern concept, many different files can use same variable.
By using include the whole file.
That's all about it.
Thanks.
"this is also a header file".
In a extern concept, many different files can use same variable.
By using include the whole file.
That's all about it.
Thanks.
Avkash Agrawal said:
1 decade ago
We know that we use many headder file such as
stdio.h, dos.h, conio.h, stdlib.h, graphics.h, iostream.h etc.
So how can you say that there is no need of this extension ?
stdio.h, dos.h, conio.h, stdlib.h, graphics.h, iostream.h etc.
So how can you say that there is no need of this extension ?
Aditya said:
1 decade ago
Header files can have any extension but it should be included with in C program with same extension.
We can define filename.c in header file.
We can define filename.c in header file.
Mani kandan said:
1 decade ago
We can define fact.c, filename.c in header file.
So, if you mention filename.c, it will read the entire file.
So, if you mention filename.c, it will read the entire file.
Ram narayan kumar said:
1 decade ago
Header files only puts the contents whatever it have on the top of program so it may have any other extension.
Lalit kumawat said:
1 decade ago
Without .h extension it is not possible to include the function like printf, scanf etc.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers