C language learned by suffering
C language learned by suffering
Writing Rules
token
Japanese sentences can be written as characters, words, sentences, paragraphs, and so on.
It can be broken down into the various elements that make up a sentence.
C programs can be decomposed in the same way.
When a C program is grammatically decomposed, the smallest unit is the token.
A token is, in essence, a word. For example, a program that begins with
but if we break this down token by token, we get the following
The reason for calling a token the smallest unit is that further decomposition would change its meaning.
For example, if return is broken down into return, an error will be displayed and the operation will fail.
It can be broken down into the various elements that make up a sentence.
C programs can be decomposed in the same way.
When a C program is grammatically decomposed, the smallest unit is the token.
A token is, in essence, a word. For example, a program that begins with
source code
int main(void) {return 0;}
but if we break this down token by token, we get the following
Token splitting
int
main
(
void
)
{
return
0
;
}
The reason for calling a token the smallest unit is that further decomposition would change its meaning.
For example, if return is broken down into return, an error will be displayed and the operation will fail.
free format
The C language is free-format , or free-format.
There are few restrictions on how programs can be written, so they can be written in any way you like.
There is only one clear rule in writing C programs.
That is to say, tokens should not be written connected to each other.
For example, you should not write your first program as shown below.
In this example, the problem is that int and main are attached to each other.
That is to say, symbols may be written by connecting them.
In the first program I created, (){}; and so on were written by connecting them together.
This is because symbols are pre-determined single characters and can be distinguished even when connected.
In the case of intmain, this appears to be nothing more than the token intmain, no matter how you look at it.
However, if it is main(void), it is obvious that it is main, (), void.
In C programs, this is the only rule of writing.
Anyway, as long as it is written without connecting any tokens other than symbols, it will be recognized.
In fact, even this program compiles without problems.
There are few restrictions on how programs can be written, so they can be written in any way you like.
Keywords.
Free format
Loose restrictions on how programs can be written, allowing free writing.
There is only one clear rule in writing C programs.
That is to say, tokens should not be written connected to each other.
For example, you should not write your first program as shown below.
Token Binding
intmain(void) {return 0;}
In this example, the problem is that int and main are attached to each other.
However, as you can see from the program we started with, there are exceptions.
That is to say, symbols may be written by connecting them.
In the first program I created, (){}; and so on were written by connecting them together.
This is because symbols are pre-determined single characters and can be distinguished even when connected.
In the case of intmain, this appears to be nothing more than the token intmain, no matter how you look at it.
However, if it is main(void), it is obvious that it is main, (), void.
In C programs, this is the only rule of writing.
Anyway, as long as it is written without connecting any tokens other than symbols, it will be recognized.
In fact, even this program compiles without problems.
Source Code
int
main
(
void
)
{
return
0
;
}
Other rules
There are other writing rules in C apart from the rules just described.
First, the C language is case-sensitive.
For example, main, MAIN, and maIN are interpreted as completely different tokens in C.
Therefore, when typing your program, be careful of the difference in case.
Also, in C, the ; symbol is supposed to be written at the end of a statement.
In the previous program, the return statement was terminated with a ;.
If you forget to do this, you will get an error.
One thing to note is that the C language cannot recognize double-byte characters.
You can use double-byte characters for things like strings displayed on the screen, but
The program itself must be typed entirely in half-width characters.
First, the C language is case-sensitive.
For example, main, MAIN, and maIN are interpreted as completely different tokens in C.
Therefore, when typing your program, be careful of the difference in case.
Also, in C, the ; symbol is supposed to be written at the end of a statement.
In the previous program, the return statement was terminated with a ;.
If you forget to do this, you will get an error.
One thing to note is that the C language cannot recognize double-byte characters.
You can use double-byte characters for things like strings displayed on the screen, but
The program itself must be typed entirely in half-width characters.
Full-width space trap
A mistake people make when writing programs is double-byte spaces.
Since a full-width space is also a double-byte character, the compiler assumes it is a mistake.
If you are using a text editor that does not display full-width spaces
It is hard to tell where the mistake is.
Since a full-width space is also a double-byte character, the compiler assumes it is a mistake.
If you are using a text editor that does not display full-width spaces
It is hard to tell where the mistake is.
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.