Array In programming, in order to handle convenience, a number of variables having the same type are organized in order. The set of these sequentially arranged similar data elements is called an array. In the C language, the array belongs to the configuration data type. An array can be broken down into multiple array elements, which can be a basic data type or a constructive type. Therefore, different types of array elements can be divided into numerical arrays, arrays, pointer arrays, structural arrays, and other categories.
This chapter introduces numerical groups and character arrays, and the rest is introduced later. Array Type Description Use an array in the C language must be described first. The general form of array description is:
Type Description A number of group names [constant expressions], ...;
Wherein, the type indicator is any basic data type or a configuration data type. An array name is a user-defined array identifier. The constant expression in square brackets represents the number of data elements, also known as the length of the array.
E.g:
INT A [10], indicating an integer array A, and 10 elements. Float B [10], C [20]; Description Real array B, 10 elements, real array C, and 20 elements. CHAR CH [20]; Description Characters CH, with 20 elements.
For array types, you should pay attention to the following points:
1. The type of array is actually an index type element. For the same array, the data types of all elements are the same.
2. The writing rules of the array name should meet the writing of the identifier.
3. A number of group names cannot be the same as other variable names, for example:
Void main () {Int a; float a [10]; ......}
it's wrong.
4. The constant expression in square brackets represents the number of array elements, such as A [5] indicates that the array A has 5 elements. However, its subscript starts from 0. Therefore, 5 elements are A [0], A [1], A [2], A [3], A [4].
5. The number of elements cannot be represented in square brackets, but may be symbol constant or constant expression. E.g:
#define fd 5void main () {Int a [3 2], b [7 fd]; ......}
It is legal. However, the following description is incorrect.
Void main () {int N = 5; int a [n]; ......}
6. Allows multiple arguments and multiple variables in the same type description.
For example: INT A, B, C, D, K1 [10], K2 [20];