Rules of Writing
token
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...
However, breaking this down token by token yields the following.
The reason tokens are called the smallest unit is because they cannot be further broken down without changing their meaning.
For example, if you break down return into ret urn, an error will be displayed and it will no longer function.
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.
For example, if you break down return into ret urn, an error will be displayed and it will no longer function.
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.
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.
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.
Since there are few restrictions on how to write the program, you can write it in a very free style.
Keyword
【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 how to write code, separate from the rules described earlier.
First, C is case-sensitive.
For example, in the C language, 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.
First, C is case-sensitive.
For example, in the C language, 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.
The Full-Width Space Trap
One common mistake when writing programs is using full-width spaces.
Since full-width spaces are also full-width characters, the compiler treats them as errors.
If you use a text editor that doesn't display full-width spaces,
it becomes impossible to tell where the errors are.
Since full-width spaces are also full-width characters, the compiler treats them as errors.
If you use a text editor that doesn't display full-width spaces,
it becomes impossible to tell where the errors are.
About This Site
Learning C language through suffering (Kushi C) isThis 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.




