What is #include <stdio.h> in a C program and why we use this in the program? How many "#include" we use in a C program. Can anyone explain me?
What is #include <stdio.h> in a C program and why we use this in the program? How many "#include" we use in a C program. Can anyone explain me?
Devoted my life to programming...
Including a file simply copies its contents into that position in the containing file.What is #include <stdio.h> in a C program and why we use this in the program?
Header (.h) files generally contain function prototypes; structs, unions, enums, and typedefs; and macros. These declare identifiers that you can then use in a particular source file without declaring them directly in that source file.
For example, when you use printf, you haven't defined that function yourself, so where does it come from? It is declared in stdio.h, and it's actual code comes from the standard library, which is automatically linked with your program when you compile.
You can use as many as you want. The current C standard library defines 29 header files. Other libraries come with their own header files.How many "#include" we use in a C program?
This is a deep psychological/philosophical question far beyond the scope of this forum.Can anyone explain me?
> What is #include <stdio.h> in a C program
Include directive - Wikipedia
> and why we use this in the program?
It saves having to manually type
extern int printf(const char *format, ... );
every time you want to print anything.
> How many "#include" we use in a C program
As many as you like.
Though you should restrict yourself to the minimum required to successfully compile your program. Unnecessary inclusion of header files will make compile times longer.
> Can anyone explain me?
Ask your parents.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
If you're learning programming, sometimes it's best to treat parts of the program as 'boilerplate' and concentrate on other things. For example, one possible 'Hello, world' program for C is
Of the 6 non-blank lines, the only one that you really have to understand is the printf line. Treat the rest as boilerplate and then heed your compiler warnings. For example, if you forgot the #include line, you will get a warning about printf. If you forgot which header file you need for printf, look it up.Code:#include <stdio.h> int main(int argc, char *argv[]) { printf("Hello, world!\n"); return 0; }
Thanks algorism,
It is damn simple. Now, i understood what it is.