That is because it is absolutely necessary for the various explanations that follow.
It's actually pretty easy to have a program do all sorts of things.
Making it understandable to humans is surprisingly difficult.
This is because the process inside a computer is nothing more than a flow of electrical signals.
Fortunately, however, it is now readily achievable.
Computers have displays.
Therefore, we can display the contents of the process on the display.
If the process is not displayed, learning programming is not possible.
The reason is that you don't know what the program did and what happened to it.
Therefore, for future programming studies, it is important to
You really need to learn how to display strings on the screen.
In other words, displaying strings on the screen is preparation for learning.
The printf function is used in the following manner.
For example, if you want to display HelloWorld, do the following
If you write this statement in your program, HelloWorld will appear on the screen.
By the way, where exactly should this statement be written?
In that sense, it is probably the most famous program in the world.
Where to write?
However, as explained at the beginning, the C language begins with the main function.
In other words, the printf function alone is not enough; the main function is always required.
For now, let us recall the main function program we created at the beginning.
We have already explained that the C language starts with the main function.
I did not explain in what order the program runs within that function.
Within a function, they simply move in order, starting with the statement above.
Then, when the return statement is reached, the function execution ends there.
For example, suppose you had a program like the following
The program runs in the order statement 1-> statement 2, and so on.
Statement 3 is ignored because the function ends with a return statement before reaching statement 3.
Given this, we can see where the printf function should be written.
In other words, you can write the following.
In fact, the program is not ready, so no text is displayed on the screen when it is run.
Some meddling compilers will get it to work...
Actually, the printf function is not a function of the C language itself.
In other words, the C compiler does not know anything about the function printf at all.
Therefore, simply writing a printf function will not work.
To make it work, you must have the compiler read the documentation for the printf function.
The C language provides special instructions for passing instructions.
It is the #include pseudo instruction.
The #include pseudo instruction can be used as follows
Since #include is an instruction that prepares the printf function, etc.
This instruction is not translated into machine language, but is processed at a preliminary stage.
#include <file name in instructions>.
The documentation for the printf function is a file called stdio.h.
In other words, you can use the printf function by adding the following program.
By the way, where should I write this order?
Since you are passing the program instructions, it must be before the program is executed.
After the program has been executed, it is too late to give the instructions.
Considering this, it would seem to be a good idea to write it at the beginning of the first line (before the main function).
In other words, a program that displays a string on the screen with the printf function would look like this
Note that #include is a pseudo instruction, so it can be written outside of a function.
Thank you for waiting
Now we finally have a program that displays strings on the screen.
The result of executing this program is as follows
In many cases, the above program is introduced out of the blue, and
#include seems to put off the explanation, assuming it is a spell.
It is said that explaining unnecessary things at the beginning can be confusing.
I'm not sure which policy is correct.
As the author, I would like to follow the policy of explaining as much as possible.
About this Site
The C language (bitter C), which is learned by suffering, is
This is the definitive C language introductory site.
It systematically explains the basic functions of the C language and
It is as complete as or better than any book on the market.