[C language] 12-array one-dimensional array

0. What is an array?

In the previous study, I learned the data types of integer, character and floating point. When facing simple problems, it is enough to use these simple data types. However, if you encounter a large amount of data, and When some processing of data is required, using the above data types is not very effective. For example, if we want to sort the scores of 50 students in the class, assuming that the scores are all integers, then we need to write 50 integer variables to store the scores of 50 students, and then sort them, which is already very complicated. , and arrays can solve this problem very well.
Arrays have the following characteristics (you don’t need to deliberately memorize it if you understand it. In fact, you will naturally know its characteristics if you use it a lot):

  1. An array is a collection of ordered data. The arrangement of each data in the array has certain rules. The subscript represents the serial number of the data in the array.
  2. An array name and subscript can be used to uniquely identify an element in an array.
  3. Each element in the array belongs to the same data type
  4. The elements in the array are stored continuously in memory, which helps to reduce the cost of memory access and improve memory utilization.

The combination of arrays and loops can effectively process large amounts of data and greatly improve work efficiency. There will be a large number of examples for readers to learn and refer to.

1. How to define a one-dimensional array

One-dimensional array is the simplest form of an array. We will learn about two-dimensional and three-dimensional arrays later. First, let’s learn the simplest one-dimensional array. Before
using an array, you need to define the array first, telling the computer how many elements the array has and what data these elements belong to. Type
The general form for defining a one-dimensional array is as follows:

类型符 数组名[常量表达式]

Guess you like

Origin blog.csdn.net/FuckerGod/article/details/132262555