learn through suffering C language learn through suffering 
C language

Rules of Writing

token

Japanese text consists of elements like characters, words, sentences, and paragraphs.
It can be broken down into its various constituent elements.
C programs can be disassembled in the same way.

When grammatically decomposing a C language program, the smallest unit is tokens.
In short, a token is essentially a word.For example, the first program we created was...

Source code
 int main(void) {return 0;}

However, breaking this down token by token yields the following.

Tokenization
int
main
(
void
)
{
return
0
;
}

The reason tokens are called the smallest unit is because they cannot be further broken down without changing their meaning.
For example, if you break down return into ret urn, an error will be displayed and it will no longer function.

free-form

C is a free-format language, meaning it has a flexible format.
Since there are few restrictions on how to write the program, you can write it in a very free style.

Keyword
【free-form】

The programming guidelines are flexible, allowing for a lot of freedom in how you write code.

There's only one clear rule when it comes to writing C programs.
It means you shouldn't write by connecting tokens.
For example, you shouldn't write your initial program like this.

Token concatenation
intmain(void) {return 0;}

In this example, the problem is that int and main are stuck together.
However, there are exceptions, as can be seen from the first program we created.
That means the symbol can be written as a continuous line.
In the first program I created, I wrote things like () {} together.

It's because the symbols are predetermined single characters, allowing them to be distinguished even when connected.
In the case of intmain, it just looks like a token named intmain.
However, with main(void), it's immediately obvious that it's main, followed by parentheses, and then void.

In C language programs, the writing rules are only these.
As long as you write them without linking non-symbol tokens, it will recognize them.
Actually, even this program can be compiled without any issues.

Source code
int
main
(
void
)
{
return
0
;
}

Other rules

C has its own rules for how to write code, separate from the rules described earlier.
First, C is case-sensitive.
For example, in the C language, main, MAIN, and maIN are interpreted as completely different tokens.
Therefore, please pay attention to the case (uppercase and lowercase) when entering the program.

In C, a semicolon (;) must be written at the end of each statement.
In the previous program, a semicolon was attached to the end of the return statement.
Please be careful not to forget this, or you'll get an error.

One important note: C does not recognize full-width characters.
You can use full-width characters for strings displayed on the screen, but...
Please enter everything in the program using only full-width characters.

The Full-Width Space Trap
One common mistake when writing programs is using full-width spaces.
Since full-width spaces are also full-width characters, the compiler treats them as errors.
If you use a text editor that doesn't display full-width spaces,
it becomes impossible to tell where the errors are.



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...