C language learned by suffering
C language learned by suffering
String display
absolutely necessary
We will now explain how to display strings on the screen.
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.
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.
printf function
To print a string in C, use the printf function.
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?
The printf function is used in the following manner.
source code
printf("string");
For example, if you want to display HelloWorld, do the following
source code
printf("HelloWorld");
If you write this statement in your program, HelloWorld will appear on the screen.
By the way, where exactly should this statement be written?
HelloWorld Program
HelloWorld appears in most introductory books.
In that sense, it is probably the most famous program in the world.
In that sense, it is probably the most famous program in the world.
Where to write?
As explained in the previous section, the printf function can be used to display text on the screen.
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.
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.
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.
Source Code
int main(void)
{
return 0;
}
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
source code
int main(void)
{
Statement 1;
statement 2;
return 0;
statement 3;
}
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.
source code
int main(void)
{
printf("HelloWorld");
return 0;
}
Importing Instructions
In the previous section, the program using the printf function should have been completed.
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
````
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.
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
pseudo instruction
A pseudo instruction is an instruction that is not program code.
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.
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.
source code
#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.
Source Code
#include <stdio.h>
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
Source Code
#include <stdio.h>
int main(void)
{
printf("HelloWorld");
return 0;
}
Note that #include is a pseudo instruction, so it can be written outside of a function.
Thank you for waiting
Thank you all for your patience.
Now we finally have a program that displays strings on the screen.
The result of executing this program is as follows
Now we finally have a program that displays strings on the screen.
source code
#include <stdio.h>
int main(void)
{
printf("HelloWorld");
return 0;
}
The result of executing this program is as follows
Execution Result
HelloWorld
Policy for bitter C
In a typical introductory C book, you'd have to skip all the explanations from chapter 1 to this point to get to the
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.
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.