As explained in the previous section, C is a free-format language.
That doesn't mean everyone has to write in a different style; it just makes the program harder to read.
Therefore, certain conventions regarding writing style are established.
The first program I created crammed everything into a single line.
Source code
int main(void) {return 0;}
Needless to say, this is an unreadable and ill-mannered program.
It is generally recommended that functions be written in the following format.
Source code
int main(void)
{
return 0;
}
Using this style makes the beginning and end of functions clearer.
indent
Let's take another look at the program we just saw.
Source code
int main(void)
{
return 0;
}
I think you'll notice that the return statement is indented too far to the right.
This is a distinctive way of writing in C, called indentation.
キーワード
【indent】
The practice of indenting text to represent hierarchy.
Indentation is used to represent hierarchical structures.
In C, it's conventional to indent the statements within curly braces {} slightly to the right.
At this time, it is customary to use the Tab key for right indenting.
Please use the tab key to indent, rather than creating space gaps.
※ところが最近では、single-byte charactersSpace4文字でずらすスタイルも結構使われていたりします・・・
If you're using a recent development environment or text editor,
It automatically indents when you input {}.
It would be easier and better if we could use an editor that automatically assigns them.
take it easy
プログラマーにとってもっとも重要なことは、take it easyことis. とにかく、コンピュータにできることはすべてコンピュータにやらせるべきis. 雑用はコンピュータに任せ、人間はより創造的な作業に取り組むようにしましょう。
comment
If it's a simple program, I can usually understand what it does just by looking at it.
As programs become more complex, their contents can be difficult to understand at a glance.
Adding comments to your program makes it more readable.
C has a feature that allows you to include explanations in your programs, and this is called a comment.
キーワード
【comment】
Comments within the program. They have no effect on how the program runs.
In C, you can make a comment by enclosing text between /* and */.
This comment has no effect on the program's execution.
Source code
int main(void)
{
/* ここがcomment */
return 0;
}
In this way, we can embed explanations within the program.
I'm repeating, comments do not affect the program's functionality in any way.
Comments can be written over multiple lines or on their own line in a program.
There aren't any established conventions for writing comments.
Some people write excessively detailed comments, while others write just a few.
However, writing absolutely no comments becomes a problem in large-scale programs.
I often forget what my own programs do.
Moving forward, the programs explained on the site will be commented where necessary.
I think you should also add comments to the programs you write yourself.
About This Site
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.