MMGames Introduction to C C Language Development Environment C language now Useful Apps Contact Us
MMGames

Automatic version identification

SpineViewer

It's easy to tell by looking at it.

Response Time Checker

I can leave my computer on and do it.

Mouse cleaning time

I can leave my computer on and do it.

Mouse cleaning time

C language learned by suffering
C language learned by suffering

Multiple variables are handled together.

Array Concepts
Until now, when declaring variables, we have always declared only one.
In some cases, however, a large number of variables may be needed.
For example, if you are creating a program to keep track of test scores for 100
Inevitably, 100 variables are needed.

There is no end to the number of variables that can be declared for each and every one of them.
In such cases, use arrays to declare multiple variables at once.
An array is a mechanism that allows multiple variables of the same type to be handled together.

Keywords.
[Array

By declaring multiple variables of the same type and managing them by number
A mechanism that allows multiple data to be handled at once.


Each variable declared as an array is distinguished by a number.
By switching the numbers around as appropriate, you can have 100's or 1000's of them.
A large number of variables can be handled in the same way.
Array Declaration
Arrays are declared as follows

array (programming, programing)
 Type name Array name[number of elements];

A type name means the same thing as the type of a variable up to now.
Variables of the type specified here are created for the number of elements.

An array name is the name of the entire array.
When individual variables are used, they are distinguished by numbering these names.

The number of elements is the number of variables to be created.
The number of variables of a given type will be created according to the number specified here.
Only integer values can be specified here as numbers.
Variables of integer type cannot be specified at the time of declaration.

These are the methods for declaring arrays.
The following is an example of declaring an array array with 100 variables of type int.

Declare array array
 int array[100];

Array handling
Arrays are handled exactly the same as variables, except that array names are numbered.
To number array names, do the following

Numbering sequence names
 Sequence name [number].

It is important to note that the numbering begins with the number 0.
For example, for the array with 100 elements declared in the previous section, the
The number that can be specified is 100, from 0 to 99, not 1 to 100.

Starting with the number 0 may seem confusing, but
Mathematically, it is more convenient in most cases to start from 0.
Adding 10 to the first number makes 10, so we can clearly see that we are 10 ahead.

As long as you are careful to start with the number 0, the rest is no different from an ordinary variable.
The following program is an example of using the 10th element of an array array.

source code
 #include <stdio.h>

int main(void)
{
    int array[100];

    array[9] = 100; /* 9 is the 10th */ because it starts from the number 0
    printf("1:%d\n", array[9]);
    array[9]++;
    printf("2:%d\n", array[9]);

    return 0;
}

The result of executing this program will be as follows

Execution Result
1:100
2:101

The results show that they are exactly the same as when using ordinary variables.


About this Site

The C language (bitter C), which is learned by suffering, is
This is the definitive C language introductory site.
It systematically explains the basic functions of the C language and
It is as complete as or better than any book on the market.

Part 0: Program Overview
  1. What is the program?
Chapter 2: How to write a program
  1. Writing Rules
  2. Writing conventions
  3. Exercise 2
Chapter 3: Display on Screen
  1. String display
  2. newline character
  3. Exercise 3
Chapter 4: Numeric Display and Calculation
  1. Numeric Display
  2. Basic Calculations
  3. Type of value
  4. Exercise 4
Chapter 5: Numerical Memory and Calculation
  1. Memorize values
  2. Variable Type
  3. Type conversion
  4. Numeric justification
  5. Exercise 5
Chapter 6: Input from the keyboard
  1. Functions for input
  2. Fear of Input
  3. Exercise 6
Chapter 9: Repetition with a fixed number of times
  1. Sentences that repeat themselves
  2. Loop Operation Mechanism
  3. Exercise 9
Chapter 10: Unknown number of repetitions
  1. Loop of unknown frequency
  2. input check
  3. Exercise 10
Chapter 13: Handling Multiple Variables at Once
  1. Multiple variables are handled together.
  2. How to use arrays
  3. Exercise 13
Chapter 19: Dynamic Arrays
  1. Create arrays at will
  2. Exercise 19
Chapter 20: Multiple Source Files
  1. Minimal division
  2. The Stone of Partition
  3. Exercise 20

Comment
COMMENT

Open the 💬 comment submission box