For example, there is a certain relationship between the fan speed and the working mode of the range hood. We can correspond its working mode with the subscript of the one-dimensional array, and we will put the specific speed in the array, which will be very convenient for us to query in the future.
For example, in the aspect of cold and warm lighting control at home, there will be two bulbs in the color temperature lamp, corresponding to cold light and warm light respectively, and the colors of the lamps will be different when different modes are selected, so we can put the brightness pwm values of these two lamps in a two-dimensional array in advance to call dimming.
Reasonable use of arrays in the program will make the structure of the program more tidy, and can transform more complex operations into simple arrays to represent them.
Extended data:
First, the rules of use:
1, only some elements can be assigned initial values. When the number of values in {} is less than the number of elements, only the previous elements are assigned.
2. You can only assign values to elements one by one, not to the whole array.
(Please note: this is true in C and C# languages, but not all places involving arrays. The database starts with 1 )
3. If no initial value is assigned to the initializable array, all elements will be 0.
4. If all elements are assigned values, the number of array elements may not be given in the array description.
Dynamic assignment can dynamically assign values to arrays during program execution. At this time, you can use the loop statement and scanf function to assign values to array elements one by one.
Second, the expression method:
Array elements are the basic units that make up an array.
An array element is also a variable, identified by an array name followed by a subscript. Subscript indicates the sequence number of the elements in the array. The general form of array elements is: array name [subscript] where the subscript can only be an integer constant or an integer expression.
If it is decimal, C compilation will be rounded automatically. For example, A [5], A [I+J] and A [I++] are all legal array elements. Array elements are also commonly referred to as subscript variables. You must define an array before using subscript variables. In C language, only subscript variables can be used one by one, and the whole array cannot be referenced at one time.
References:
Baidu Encyclopedia-Array