Friday, March 16, 2012

Write A Program Without Using Header File in C.

No comments

/*It is complied on Turbo C++ 3.0*/  

We can write a program without using header-file in C language. First of All I will give a simple example to understand this concept. See the example:
        #include<stdio.h>
        #include<conio.h>
              void main ( )
                    {
                          int num1,num2,sum; /*This is integer type variable  declaration*/

                          clrscr ( ) ;
                          printf("\n Enter Two Numbers :: ");
                          scanf("%d%d",&num1,&num2);
                         printf("\n The Sum is :: %d",(num1+num2));
                         getch();
                   }
                  
We all know that It is the simplest program for addition of two number. It will simple return the sum  of two number. If  We enter two number number 10 and 12. It will return 22.
But If we remove the all header files then the remaining program will be.. 
              void main ( )
                    {
                          int num1,num2,sum; /*This is integer type variable  declaration*/
                          clrscr ( ) ;
                          printf("\n Enter Two Numbers :: ");
                          scanf("%d%d",&num1,&num2);
                         printf("\n The Sum is :: %d",(num1+num2));
                         getch();
                   }
Does it work like before ?
Answer is Yes . It will work and return right answer like before.

Why is It ?
When we write any program in C without using header files and compile the program. It (before save the program) will show many error but when we save this program with .C extension. By default compiler include all necessary header file and program will successfully run.
But Some times It may show error for some header files like math.h .

Simple step to write program without using Header files.


  1. Start your program form void main( )
  2. Complete your program.
  3.  Don't compile it now just save it with .C extension then compile.
  4. Finally Run Your Program and Get result.
It is trick. Not a concept, So for better result use header file when creating a bigger program.
I check it in Turbo C++ 3.0
Try it in Different compiler and comment here so that other can know...




0 comments:

Post a Comment

Entries RSS Comments RSS

Sample Text

Pages


Copyright © Lovely Codes
Powered by Blogger
Distributed By Free Blogger Templates | Design by N.Design Studio
Blogger Theme by Lasantha - PremiumBloggerTemplates.com