1.2 C Language---arrays
1.2.1 Why arrays are introduced?
An array is a group of numbers, which is a variable of a particular data type, and the group is saying that the majority is put together.
1.2.2 How to define an array?
int a[4]; Defines an array a with 4 int elements.
Summary: All elements in an array must be of the same data type, and it is not possible to store the number of two data types in an array.
1.2.3 How to use arrays?
Defined as a whole when the array is defined. However, when used, it cannot be used as a whole, and each element in the array must be disassembled when used.
For example: int a[4], using one of the four elements, respectively, with A[0] 、、、 a[3], where [] is an array of flags, [] The number is called an array subscript (index, indexed), subscript gives us access to the elements in the array guidelines. The subscript is 0 for the first element in the array, the subscript is 1 for the second element of the array. If the array length is n, the last one in the subscript is n-1. When accessing an array, pay special attention to the subscript, which starts at 0, and if the subscript exceeds the n-1, it generates a monthly access and the result is unpredictable.
1.2.4 Initialization (initinalize, abbreviated INIT) is to allow the object to have a predetermined initial state.
(1) Initialization of variables
When a variable is defined without initialization, its value is random. If this is not noticed, it may cause a program error.
The solution has two:
The first one: after the definition, it is definitely assigned value;
The second: When the variable is defined, it is initialized at the same time.
Summarize:
A, in general, as long as you remember to display the assignment, there is no difference between the pros and cons of the two methods. But people can make mistakes, will be careless, so the second definition is also initialized at the same time, because this time the definition of the value is fixed, even if you forget to display the assignment will not cause the result is random.
B, in general, the definition of the variable is initialized to 0, the local variable definition is also initialized to 0, which is a good habit of writing code.
(2) Initialization of arrays
The first type: full initialization. One assignment at a time.
The second type: not fully initialized. Assignment in an initializer.
This article is from the "snail" blog, make sure to keep this source http://datacloud21.blog.51cto.com/9561292/1922194
1.2 C Language---arrays