Answered by:
can a C/C++ prog. runs without header file

Question
-
can any1 tell me tht,
is there any way thro which a C/C++ prog. executes without
using any header file...Friday, March 30, 2007 7:59 PM
Answers
-
hhhhhmmmmmmmmmm..........
well although not too gud in C/C++ but as far as i know!!! !! !
if u want to run it widout header file den u hve to include all the header files before compilation!!!
which is useless....cause those header file might get included which r not to b used!!! !! !
effectin 1 point for gud programming skill!!!!!!
Saturday, March 31, 2007 6:35 AM -
main()
{
printf("hi");
}
try this it wont require any header file....
Monday, April 2, 2007 12:09 AM -
well NISHANT
u said tht,
at the compilation time u can include all the header files...
i don't understand what u said, coz header files r writen in the starting....
Thursday, April 5, 2007 10:49 PM -
yups , he must hav to say tht wat exactly
he wants...
Thursday, April 5, 2007 10:52 PM -
It is possible to run a c / C++ Program without a header File ..To do so u have to write the code of the entire header files .....Else it is impossible ...Tuesday, April 10, 2007 8:11 PM
-
@varun
m asking for a shortcut one not a super long one....
CLUE: if u change the extension fm .cpp to .c then it may run.....
i don't the ans. but i learned this fm somewhere else....
this is not working on my side...may b it wil run on ur system coz it might b Compiler depended.....m not sure...Wednesday, April 11, 2007 7:20 PM -
Sanket_Shah_734609 wrote: @ Varun,
The idea of yours is the most silly thing to do.
Silly it is, but its better than writing all of the header contents on your own..I just gave a possible answer..
Also, using printf & scanf without header file is compiler dependent.. some of the compiler would allow you to do it some will not.. Also there are different versions of Turbo C, so it can create a difference too.. but the thing is that you can write a C/C++ prog without the header file...
But, Anyways header file only include the Prototype of the functions that we are going to use.. It does not contain the whole code.. Like there is only the prototype of printf and scanf in stdio.h
So just check out the prototype of the functions and declare them your self.. this will be enough to run your program.. you can do this for any funtions that you use.. you only need to declare the prototype of the function.. The linker will attach this funtions to your code at the time of linking...Thursday, April 12, 2007 3:21 AM -
dear frind the program can very well run without header files until u use header file functions.
eg
void main()
{
int i=0;
i=i+1;
}
this program increments the value of i but does not display it on screen.
else define the standard funct. like clrscr(), printf(), etc by urself and then use them
Saturday, April 14, 2007 9:39 AM -
@sanket
had you checked Kanav post???
Saturday, June 30, 2007 11:47 AM -
10x dudes..
A C program can only run without Header files(only on certain conditions)
but a C++ can't run without header filesWednesday, September 12, 2007 10:34 AM
All replies
-
hhhhhmmmmmmmmmm..........
well although not too gud in C/C++ but as far as i know!!! !! !
if u want to run it widout header file den u hve to include all the header files before compilation!!!
which is useless....cause those header file might get included which r not to b used!!! !! !
effectin 1 point for gud programming skill!!!!!!
Saturday, March 31, 2007 6:35 AM -
Well the answer is yes.. because in some compilers the functions of printf and scanf are integrated in the compiler, so you dont need to declare a header file for them.. so you can run a program which has only a printf and scanf function without the header file...'Sunday, April 1, 2007 6:08 AM
-
Yes, you can do that. But the way is very difficult. You need to write whole functions and methods before using them, which is not the case when you use pre-compiled header file.Sunday, April 1, 2007 4:41 PM
-
Ya thatz true.. but the thing is that you can write a program without header files... n that is a factSunday, April 1, 2007 4:53 PM
-
I know that, but you must give strong grounds to believe it. So please give appropriate responses next time.Sunday, April 1, 2007 6:29 PM
-
main()
{
printf("hi");
}
try this it wont require any header file....
Monday, April 2, 2007 12:09 AM -
This code definitely uses header files. The functions are assumed to be available from standard location of header files as defined by development environment.
So, the baseline is, you can't write a program without header files, until and unless you define functions by your own.Monday, April 2, 2007 6:16 PM -
well NISHANT
u said tht,
at the compilation time u can include all the header files...
i don't understand what u said, coz header files r writen in the starting....
Thursday, April 5, 2007 10:49 PM -
yups , he must hav to say tht wat exactly
he wants...
Thursday, April 5, 2007 10:52 PM -
it wont work..Thursday, April 5, 2007 10:53 PM
-
It is possible to run a c / C++ Program without a header File ..To do so u have to write the code of the entire header files .....Else it is impossible ...Tuesday, April 10, 2007 8:11 PM
-
Or the best of all, just copy the whole header file in the program
, It is equivalent to include the file, but you are not doing it explicitly...
Wednesday, April 11, 2007 3:22 AM -
@ Varun,
The idea of yours is the most silly thing to do.Wednesday, April 11, 2007 7:02 PM -
@varun
m asking for a shortcut one not a super long one....
CLUE: if u change the extension fm .cpp to .c then it may run.....
i don't the ans. but i learned this fm somewhere else....
this is not working on my side...may b it wil run on ur system coz it might b Compiler depended.....m not sure...Wednesday, April 11, 2007 7:20 PM -
Sanket_Shah_734609 wrote: @ Varun,
The idea of yours is the most silly thing to do.
Silly it is, but its better than writing all of the header contents on your own..I just gave a possible answer..
Also, using printf & scanf without header file is compiler dependent.. some of the compiler would allow you to do it some will not.. Also there are different versions of Turbo C, so it can create a difference too.. but the thing is that you can write a C/C++ prog without the header file...
But, Anyways header file only include the Prototype of the functions that we are going to use.. It does not contain the whole code.. Like there is only the prototype of printf and scanf in stdio.h
So just check out the prototype of the functions and declare them your self.. this will be enough to run your program.. you can do this for any funtions that you use.. you only need to declare the prototype of the function.. The linker will attach this funtions to your code at the time of linking...Thursday, April 12, 2007 3:21 AM -
Hey Varun,
Check out the contents of header file. It also contains some system defined declarations that are needed for different functions to work. Moreover, each function has a specific way to call function from the object file, as header files just contain calls to object files.
It you know how to write all those things, alongwith writing your own code to call for display / reading, then you can write your program without including header files.Friday, April 13, 2007 12:44 PM -
dear frind the program can very well run without header files until u use header file functions.
eg
void main()
{
int i=0;
i=i+1;
}
this program increments the value of i but does not display it on screen.
else define the standard funct. like clrscr(), printf(), etc by urself and then use them
Saturday, April 14, 2007 9:39 AM -
Yours is really a nice reply Kanav.
You deserve getting your reply marked as answer.
Saturday, April 14, 2007 10:40 AM -
@sanket
had you checked Kanav post???
Saturday, June 30, 2007 11:47 AM -
Kanav's reply was excellent... In effect, you can write any program without including any header files as long as you stick to basic C. I/O and floating point are not defined to be within basic C language itself, so you'll have to include header files for using them. Other than that, we can use all declarations, assignments, calculations, looping, branching, etc., without using any header files at all...
Even for I/O, you might be able to do it yourself using low level manipulation. For eg., I remember reading in 'Let us C' by Yashavant Kanetkar that you can output text the monitor by storing the address of video memory in a far pointer and writing the content to it... Quite some work, but possible...Thursday, September 6, 2007 5:13 AM -
10x dudes..
A C program can only run without Header files(only on certain conditions)
but a C++ can't run without header filesWednesday, September 12, 2007 10:34 AM -
Hey Buddy,
As i know there is no way to compile C/C++ files without header files.
As the maker of C/C++ compiler has explicitely made the header file for individual compiler and without that your program can not be indentified as it is of C or C++.
And as the above person said that u can include before compiling that means you are including files to program.......
And ya if you got any other way to do it the ndo reply here... I would like to learn new things about C/C++ programs
Hope i have been able to satisfy your query....Wednesday, September 12, 2007 12:35 PM -
Well Denish, I dont know if you have studied the System softwares yet or not, but when you will study the linker in System Software, you will realise that its possible to run a program without a header file, as header file only contain the prototype of the functions that we use.. this functions will get attached to our program at the time of linkage...Wednesday, September 12, 2007 2:30 PM
-
Denish_Gandhi_04b0f5 wrote: Hey Buddy,
As i know there is no way to compile C/C++ files without header files.
As the maker of C/C++ compiler has explicitely made the header file for individual compiler and without that your program can not be indentified as it is of C or C++.
And as the above person said that u can include before compiling that means you are including files to program.......
And ya if you got any other way to do it the ndo reply here... I would like to learn new things about C/C++ programs
Hope i have been able to satisfy your query....Well my friend, i m giving you a smalll work to do.
after doing your homework reply here.
WAP to display your name by:
1) including header file stdio.h or iostream.h
2) without using any of these header files.
Waiting for your reply..
Akshat
Wednesday, September 12, 2007 2:49 PM -
Usually a beginner used to get these kind of problems , ie errors like unable to include files , here ill explain you why !
In your C/C++ programs u might use some functions or objects , upon using this you have to declare those objects before using in your program , if in case its a function you have to declare function prototypes , this is must in C++ , these declarations are available in header files
eg : the definition for the object 'cout' is available in the header file iostream.h
So once if you compile a program , the compiler tries to make reference with those header files, matter of fact compiler don't know the exact locations of header files , By default the compiler vendors will guide the compiler by providing path names. by mistake if there is a change in the path name , then the compiler fails to make a reference with the header file
if so you used to get the familiar error message in Turbo C/C++
Error : Unable to include IOSTREAM.H and so on .
Solution :
Try to find the path where the header files are stored ( hope it will be available under TC\INCLUDE\ directory
Open the OPTION menu from your IDE select Directories , there you supposed to enter the absolute path where your header files stored in your disk .
Enter the path name , press OK
Re-compile the program , sure you won't get any errors
Regards
Prince M. PremnathThursday, September 13, 2007 6:55 AM -
int main()
{
printf("\n hi");
getch();
return 0;
}
this code worked on devc++
remember this file havingf a .c extention
so header file inclusion is not necessary :-Saturday, September 15, 2007 12:59 PM -
Saturday, September 15, 2007 2:36 PM
-
Well to answer all your queries... have a look at this code.. I hv declared the printf and scanf functions on my own and used them... The linker will directly attach the object codes of the functions at linking.... I have compiled and run this program in VC++ 98
test.cint scanf(const char *, ...);
int printf(const char *, ...);
void main()
{
int i;
scanf("%d", &i);
printf("This is test, value of i = %d", i);
}Saturday, September 15, 2007 3:26 PM -
If the extension is .c, then th compiler (TC) will automatically get the header files from the standard header directory that is pre-set.
if the extension is .cpp, then the compiler will give error, cause it will not load the library automatically for you.
Yes, you can write a program entirely without header files. Header files are used to reduce the coding for the application programmers. And hence if you know how to write the code that comes inbuilt in the standard header files, then yes you can create an antire program without header files.
The header files that are inbuilt also dnot contani the actual code, they just contain the function declarations and their usage ( in short prototypes). The actual code lies in machine language which is precompiled by the compiler designers in binary format. The header files will just give you interface to use those libraries.
To add something more : you can also write assembly code in your c program.Monday, September 17, 2007 5:33 PM -
ya u can write it but u should write a seperate function n cal it for ex u r using math.h means u should write a whole functions which r present in math.h in seperate file n u should cal tat function ya but its very very difficultMonday, September 24, 2007 2:52 PM
-
Yes You can execute till you didn't use any header file functions like-
void main()
{
}
or
in some compilers like turbo c
you can use printf and scanf without inlucind header files like-
void main()
{
printf("HEllo World");
}Monday, September 24, 2007 3:30 PM