Japanese text consists of elements like characters, words, sentences, and paragraphs.
It can be broken down into its various constituent elements.
C programs can be disassembled in the same way.
When grammatically decomposing a C language program, the smallest unit is tokens.
In short, a token is essentially a word.For example, the first program we created was...
Source code
int main(void) {return 0;}
However, breaking this down token by token yields the following.
Tokenization
int
main
(
void
)
{
return
0
;
}
The reason tokens are called the smallest unit is because they cannot be further broken down without changing their meaning.
たとえば、return を、ret urn にminute解すると、Errorが表示され、動作出来なくなります。
free-form
C is a free-format language, meaning it has a flexible format.
Since there are few restrictions on how to write the program, you can write it in a very free style.
キーワード
【free-form】
The programming guidelines are flexible, allowing for a lot of freedom in how you write code.
There's only one clear rule when it comes to writing C programs.
It means you shouldn't write by connecting tokens.
For example, you shouldn't write your initial program like this.
Token concatenation
intmain(void) {return 0;}
In this example, the problem is that int and main are stuck together.
However, there are exceptions, as can be seen from the first program we created.
That means the symbol can be written as a continuous line.
In the first program I created, I wrote things like () {} together.
"It's because the symbols are predetermined single characters, allowing them to be distinguished even when connected."
"In the case of intmain, it just looks like a token named intmain."
"However, with main(void), it's immediately obvious that it's main, followed by parentheses, and then void."
"In C language programs, the writing rules are only these."
"As long as you write them without linking non-symbol tokens, it will recognize them."
Actually, even this program can be compiled without any issues.
Source code
int
main
(
void
)
{
return
0
;
}
Other rules
C has its own rules for writing code, separate from the guidelines previously mentioned.
First, C is case-sensitive.
For example, in C, main, MAIN, and maIN are interpreted as completely different tokens.
Therefore, please pay attention to the case (uppercase and lowercase) when entering the program.
In C, a semicolon (;) must be written at the end of each statement.
In the previous program, a semicolon was attached to the end of the return statement.
Please be careful not to forget this, or you'll get an error.
One important note: C does not recognize full-width characters.
You can use full-width characters for strings displayed on the screen, but...
Please enter everything in the program using only full-width characters.
Learning C language through suffering (Kushi C) is
This is the definitive introduction to the C language.
It systematically explains the basic functions of the C language.
The quality is equal to or higher than commercially available books.