There are two ways to assign values to an array variable:
(1) name = (value1... valuen) The subscript starts from 0.
(2) name [index] = value
Arrays are a form of organizing several variables of the same type in order to facilitate processing in programming. The collections of these sort-by-order data elements are called arrays. In C, arrays are constructed data types. An array can be divided into multiple array elements, which can be basic data type or constructor type. Therefore, Arrays can be divided into numeric arrays, character arrays, pointer arrays, Structured arrays, and other categories based on the types of array elements.
Array type
1. the array type is actually the value type of the index group element. For the same array, the Data Types of all its elements are the same.
2. The writing rules of array names should comply with the writing rules of identifiers.
3. the array name cannot be the same as other variable names.
Related rules
1. Only initial values can be assigned to some elements. When the number of {} values is less than the number of elements, only the previous element is assigned a value. For example, static int a [10] = {0, 1, 2, 3, 4}; indicates that only a [0] ~ A [4] assigns values to five elements, and the last five elements are automatically assigned 0 values.
2. You can only assign values to elements one by one, but not to the entire array. For example, if one value is assigned to all ten elements, the value can only be set to static int a [10] = {,}, but cannot be set: static int a [10] = 1; (Note: this is true in C, but not in all places involving arrays)
3. If no initial value is assigned to the initialized array, all elements are 0.
4. If you assign values to all elements, you can leave the number of array elements in the array description. For example: static int a [5] = {1, 2, 3, 4, 5}; can be written as: static int a [] = {1, 2, 3, 4, 5 }; you can assign values to arrays dynamically during program execution. In this case, the circular statements can be used with the scanf function to assign values to array elements one by one.