Conventions of writing
How to write functions
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.
Needless to say, this is an unreadable and ill-mannered program.
It is generally recommended that functions be written in the following format.
Using this style makes the beginning and end of functions clearer.
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.
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.
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.
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.
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.
Keyword
【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.
The mainstream in recent years is half-width spaces.
In recent years, it has become standard practice to use half-width spaces instead of tabs to ensure consistent width across all computers.
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
The most important thing for programmers is to make things easy for themselves. In short, anything a computer can do should be done by a computer. Let computers handle the menial tasks, and let humans focus on more creative work.
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.
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.
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.
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.
Keyword
【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)
{
/* This is a 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.
Source code
int main(void)
{
/*
This, all of this,
commentIt is.
*/
return 0; /* This is also a comment */
}
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) 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.




