C language learned by suffering
C language learned by suffering
Programs that do nothing
C Language Structure
We will now create our first program in C.
However, it is impossible to create a program with many different functions from the beginning, so
We start by creating a program that has no function and does nothing.
By the way, what kind of knowledge is needed to create a C program?
Whatever you are going to make, you will not be able to make it without knowing its structure.
To build a bookshelf, you need to know the structure of a bookshelf, and the same is true for the C language.
So what exactly is the structure of the C language?
When building a machine, we put together various components.
Similarly, programming combines parts. These parts are called functions.
In other words, a C program is made up of a collection of functions.
It is important to note that this is a collection of functions, not a sequence of functions.
When we speak of a sequence, we mean that it has an order.
However, when we speak of a collection, there is no order to it.
With one partial exception, C functions have no concept of order at all.
The structure of a C program is a collection of various functions, each of which is called a "function".
Each function can be used in any order.
However, it is impossible to create a program with many different functions from the beginning, so
We start by creating a program that has no function and does nothing.
By the way, what kind of knowledge is needed to create a C program?
Whatever you are going to make, you will not be able to make it without knowing its structure.
To build a bookshelf, you need to know the structure of a bookshelf, and the same is true for the C language.
So what exactly is the structure of the C language?
When building a machine, we put together various components.
Similarly, programming combines parts. These parts are called functions.
In other words, a C program is made up of a collection of functions.
Structure of C Language Programs
A C program is made up of a collection of functions.
It is important to note that this is a collection of functions, not a sequence of functions.
When we speak of a sequence, we mean that it has an order.
However, when we speak of a collection, there is no order to it.
With one partial exception, C functions have no concept of order at all.
The structure of a C program is a collection of various functions, each of which is called a "function".
Each function can be used in any order.
How to Create Functions
We have seen that the structure of a C program is a set of functions.
Then, the next problem is naturally the structure of functions.
Functions in C have a very clear structure. The following is the structure of a C function.
A type name is the type of number that a function uses to return the result of a calculation.
Here, for now, remember the type int (int).
The word int means an integer.
A function name is literally the name of a function.
The naming convention is as follows.
Reserved words are keywords used in the C language.
However, the number of these reserved words is small and not very important.
Any name is acceptable, as long as it meets the requirements I mentioned earlier.
For now, we will use the name main (main).
An argument is a type of number that is passed to a function.
Functions can perform calculations and return results based on the numbers passed to them.
However, as mentioned at the beginning, the purpose of this project is to create a program that does nothing.
There would be no need to pass information to a program that does nothing.
Therefore, we will use void, which represents the absence of information.
Processing is exactly what the name implies.
As I mentioned at the beginning, our goal this time is to create a program that does nothing.
The only process that must be done this time is to terminate the function.
To terminate a function, use the return statement.
Note that the return statement has the ability to return the numerical value of the result of the calculation.
In this case, since the program does nothing, we will leave it at 0 for now.
With the above, the following function is completed.
The {} and ; are explained later.
Then, the next problem is naturally the structure of functions.
Functions in C have a very clear structure. The following is the structure of a C function.
Function Structure
Type Function name (Argument) {Processing}
A type name is the type of number that a function uses to return the result of a calculation.
Here, for now, remember the type int (int).
The word int means an integer.
A function name is literally the name of a function.
The naming convention is as follows.
Name Conventions
1, One-byte alphabets, one-byte numbers, and one-byte _ (underbar) can be used.
2. Numbers cannot be used as the first character.
3、Pre-determined reserved words cannot be used.
2. Numbers cannot be used as the first character.
3、Pre-determined reserved words cannot be used.
Reserved words are keywords used in the C language.
However, the number of these reserved words is small and not very important.
Any name is acceptable, as long as it meets the requirements I mentioned earlier.
For now, we will use the name main (main).
reserved identifier
In C, reserved words as well as reserved identifiers cannot be used as names.
A reserved identifier is a name that is used internally, and
Names followed by an underscore capital letter cannot be used, and
The standard names used in the C language cannot be used.
A reserved identifier is a name that is used internally, and
Names followed by an underscore capital letter cannot be used, and
The standard names used in the C language cannot be used.
An argument is a type of number that is passed to a function.
Functions can perform calculations and return results based on the numbers passed to them.
However, as mentioned at the beginning, the purpose of this project is to create a program that does nothing.
There would be no need to pass information to a program that does nothing.
Therefore, we will use void, which represents the absence of information.
Processing is exactly what the name implies.
As I mentioned at the beginning, our goal this time is to create a program that does nothing.
The only process that must be done this time is to terminate the function.
To terminate a function, use the return statement.
Note that the return statement has the ability to return the numerical value of the result of the calculation.
In this case, since the program does nothing, we will leave it at 0 for now.
With the above, the following function is completed.
source code
int main(void) {return 0;}
The {} and ; are explained later.
The main function is a special
Now, let's get right to programming with the completed function...
But first, there is one more thing you need to know.
In section 1, we explained that there is no order in functions.
However, this leaves one in a bind.
First of all, I am not sure which function to look at first.
The C language solves this problem in a very simple way.
In the C language, the function named " main " is determined to be the first to work.
If the main function is nowhere to be found in the program, then the
Since the first function is gone, the program cannot work.
Conversely, a C program can run as long as it has a main function.
The function we just created is named main.
With this function, the program can be made to run.
But first, there is one more thing you need to know.
In section 1, we explained that there is no order in functions.
However, this leaves one in a bind.
First of all, I am not sure which function to look at first.
The C language solves this problem in a very simple way.
In the C language, the function named " main " is determined to be the first to work.
Meaning of main function
A C program is made up of a collection of functions.
In C, the main function is the first one to work.
In C, the main function is the first one to work.
If the main function is nowhere to be found in the program, then the
Since the first function is gone, the program cannot work.
Conversely, a C program can run as long as it has a main function.
The function we just created is named main.
With this function, the program can be made to run.
Running the program
Now, let's run the program.
This is the program we created that does nothing.
Type this program according to the compiler's instructions.
However, do not copy and paste text from your browser.
To familiarize yourself with typing the program, please type it from the keyboard.
If you do not already have a compiler, please download it here.
Learning C Language Development Environment
After typing it in, try to get it running as soon as possible.
The result of executing this program will be as follows
Nothing seems to be showing up. Congrats!
The results were in line with our goal of creating a program that does nothing.
Note that in many environments, you will see a variety of text.
They have nothing to do with the operation of the program and should be ignored.
This is the program we created that does nothing.
source code
int main(void) {return 0;}
Type this program according to the compiler's instructions.
However, do not copy and paste text from your browser.
To familiarize yourself with typing the program, please type it from the keyboard.
If you do not already have a compiler, please download it here.
Learning C Language Development Environment
After typing it in, try to get it running as soon as possible.
The result of executing this program will be as follows
Execution Result
Nothing seems to be showing up. Congrats!
The results were in line with our goal of creating a program that does nothing.
Note that in many environments, you will see a variety of text.
They have nothing to do with the operation of the program and should be ignored.
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 more complete than any book on the market.