Saturday, May 22, 2010

Is it necessary to include stdio.h in c compiler?

if we use printf function

Is it necessary to include stdio.h in c compiler?
If you are using pure C compiler there is no need to include stdio.h...( printf,scanf)


But if you are using c++ compiler for c programs you will have to include this...





Most probably you will be using a C++ compiler...





printf(),scanf() like functions are written in stdio.h which also called standard Input/Output library.





But to include some functions other than printf and scanf, stdio.h also needs to be included in pure C compiler as well.
Reply:Yes, It is necessary to include stdio.h in C program, if you use printf function. As the declaration of printf is in this file only.
Reply:Well,if you're using Turbo C++ Or Turbo C,then before creating your program,you better save the file with extension .C,suppose you want to make a program named My Program...so you click on the save as option from file menu,then save it as My Program.C{.c is the extension of C}





Now,there is no need to include any library functions like stdio.h,conio.h,math.h and so on..





When you give extension ''.c'' to anyfile,it includes all the library functions within it...no need of separate inclusion of #include %26lt;stdio.h%26gt; %26amp; so on..
Reply:Well, if you are using a genuine copy of C compiler then you won't have to use the statement: #include %26lt;stdio.h%26gt; but you may have to use it if the compiler is not a egnuine or doesn't contain all the necessary "include" files.





If you are working in IDE of C++ compiler then you must include that statement.





Note-%26gt; stdio.h is a header (.h) file and stdio stands for Standard Input/Output.
Reply:Only if you want to have the ability to handle standard i/o, such as printing to screen or printer or piping from one program to another.





I can't think of any time when you wouldn't want to include it except in some embedded situation.


No comments:

Post a Comment