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?
Yes
No
Answer: Option
Explanation:

No, the header files have any kind of extension.

Discussion:
16 comments Page 2 of 2.

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.

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.

Bhawna said:   1 decade ago
Please elaborate the answer.

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!

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.

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.


Post your comments here:

Your comments will be displayed after verification.