MMGameslogo  MMGames
TwitterSharebutton  FacebookSharebutton   
learn through sufferingC Language
learn through sufferingC Language

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.

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.

Source code
int main(void)
{
    /*
    これは、これ全部が、
    commentis.
    */
    return 0; /* ここも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) 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.

Part 0: Program Overview
  1. What is a program?
Chapter 3: Displaying on the Screen
  1. String Display
  2. newline character
  3. Practice Problem 3
Chapter 4: Displaying and Calculating Numbers
  1. Display of numbers
  2. Basic calculations
  3. Numeric types
  4. Practice Problem 4
Chapter 6: Input from the Keyboard
  1. input function
  2. The fear of input
  3. Practice Problem 6
Chapter 9: Repeating a Fixed Number of Times
  1. Iterative sentence
  2. How Loops Work
  3. Practice Problem 9
Chapter 10: Repeating Without Knowing the Number of Times
  1. Unspecified loop
  2. Input validation
  3. Practice Problem 10
Chapter 13: Handling Multiple Variables at Once
  1. Handling multiple variables collectively.
  2. Arrays
  3. Practice Problem 13
Chapter 19: Dynamic Arrays
  1. Create arrays freely.
  2. Practice Problem 19