C++ : is what the meaning of #include<stdio.h>?

Hello Guys,

I'm new in programing line & just started from C++ programs but i don't know the meaning of #include<stdio.h> file....Guys tell me what's the working of this file in C++ program?? I'm confused...

Early in the compiling of a source, a preprocessor takes these # directives. #include basically puts all of stdio.h into the top of your code. the .h identifies it as a "header".

In C, before you use a function, the compiler must first know how it is suppose to be called.

For example, how many arguments and of what type? All this is in stdio.h, for the Standard I/O functions (things that print to the screen and such).

Usually, in C++ it's #include <iostream> , but we won't fault you for using C functions :slight_smile:

Why this is needed in C goes to the heart of how C compiles and links.

Including <stdio.h> tells the compiler that "somewhere, there exists a function named fgets, which takes arguments of char *, int, and FILE *". So the compiler will assume that function exists, not complain about it when you use it, and get the arguments right without guessing. It doesn't need the function itself yet.

Later, when it links your program, it assembles everything from pieces and when it hunts for this name, it will find it in the standard libc library.

Once it's done piecing all these bits together, what it gives you is a program that can be loaded in memory, which is the bit you actually run.

1 Like

On another note the headers, on Gnu/Linux, are to be found at /usr/include. If you get an error you can do "man 3 printf" (if the function you use is printf) and the man page will tell you which header you need to include.