Tuesday, 13 August 2013

C/C++ program without header files

C/C++ program without header files

I was wondering if there is any possible way to write C/C++ program
without using header files at all.
#include <iostream.h> //I want this same code to work without including
this line
#include <conio.h> //I want this same code to work without including
this line
int main ()
{
clrscr();
char str [80];
int num;
cout<<"Enter the string : "<<str;
cin>>str;
cout<<"Enter the number : "<<num;
cin>>num;
getch();
return 0;
}
I learned that in C we can use scanf() function without using stdio.h
Example:
#include <stdio.h>
int main ()
{
char str [80];
scanf ("%s",str);
return 0;
}
The above code can be written as
extern int scanf(const char *format, ...);
int main ()
{
char str [80];
scanf ("%s",str);
return 0;
}
Here by calling extern int scanf(const char *format, ...);, scanf() will
work seamlessly.

No comments:

Post a Comment