learn through suffering C language learn through suffering 
C 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.

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.

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) 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. line break
  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

Loading comment system...