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

A do-nothing program.

Structures in C
Now, we're going to create your first program in C.
However, it's impossible to create a program with various functions from the beginning,
"We'll start by creating a program that does nothing – a do-nothing program."

By the way, what kind of knowledge is needed to write C programs?
Whatever you build, you can't build it without knowing its structure.
To build a bookshelf, you need to know its structure, and the same is true in C.

So, what exactly is the structure of a C struct?
When making a machine, it's made by combining various parts.
Similarly, in programming, you combine components.This component is referred to as the function.
In essence, C programs are built from collections of functions.

The Structure of a C Program
C programs are built by collections of functions.

The key thing to note here is not the order of the functions, but rather a collection of functions.
When we talk about ordering, it implies having an order.
However, when it comes to a gathering, there's no order to it.

C functions, with a few exceptions, have no concept of order.
The structure of a C language program is one composed of various functions bundled together.
Each function can be used in any order.
How to create functions
It has become clear that the structure of a C language program is a collection of functions.
Then, the next issue that naturally arises is the structure of the function.

C functions have a very clear structure.The following is the structure of a C function.

Function Structure
typename functionName(arguments) { processing }

Return type refers to the type of numerical value used when a function returns a result.
Just for now, please remember the type called int.
"int stands for integer."

Function name literally means the name of a function.
There are certain rules for naming like this.

Naming conventions
1、single-byte charactersalphabet、single-byte charactersdigit、single-byte characters_(アンダーバー)が使える。
"2. Numbers cannot be used as the first character."
3、あらかじめ決められたReserved wordsは使用することが出来ない。

"Reserved words are keywords used in the C language."
However, the number of these keywords is small, so it's not something to worry too much about.


"If the previous conditions are met, any name will do."
For this time, let's try using the name main.

Reserved identifier
C languageでは、Reserved wordsの他、Reserved identifierも名前として使用できません。
Reserved identifierは、内部で使用される名前のことで、
アンダーバーに大文字が続く名前は使用できませんし、
C languageで標準的につかわれる名前も使用できません。

An argument is the type of value passed to a function.
A function can calculate a result based on the given number.
However, as mentioned earlier, the goal of this exercise is to create a program that does nothing.
There's no need to pass information to a program that does nothing.
Therefore, we will use void to represent the absence of information.

Processing is processing, as the name suggests.
As I mentioned earlier, the goal of this exercise is to create a program that does nothing.
This time, the only necessary task is to terminate the function B.
To exit a function, use the `return` statement.
Furthermore, the return statement has the functionality to return a numerical result.
Since this is a program that doesn't do anything this time, I'll just set it to 0 for now.

As such, the following function was completed.

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

Furthermore, I will explain the { } and ; later.
The main function is special.
Now, let's dive right in and try some programming using the completed function.
But before that, there's one more thing you need to know.

In section 1, we explained that functions have no order.
However, this creates one problem.
"First, I'm unsure which function to start with."

In C, this problem is solved in a very straightforward way.
In C, a function named main is designated to be the first one that runs.

Meaning of the main function
C programs are built by collections of functions.
C languageでは、mainfunctionが1番始めに動作する

If there were no main function anywhere within the program,
The program won't work because the first function is gone.
Conversely, if you have a main function, a C program can run.

The function I just created is named "main", so...
With this function, we can run the program.
Run the program.
Let's run the program now.
This is the do-nothing program I've created this time.

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

Please type in this program according to the compiler's explanation.
However, please do not copy and paste text from the browser.
Please type using the keyboard to get used to entering programs.

If you don't already have a compiler, please download it from here.
Learning C Development Environment

"Once you've entered it, please run it right away."
The results of this program's execution are as follows:

Execution results

It looks like nothing is showing.Congratulations!
The result was exactly as intended: a program that does nothing.
In many environments, various texts will be displayed.
Please disregard them as they are not related to the program's operation.


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