Array notes, array
1. array definition:
Array type array name [length]; length must be an integer greater than 0
/*
In this sentence, the length of the number array must be specified.
It cannot be written as follows:
Int a [I];
I = 10;
It should be written:
Int a [10];
You can also use macro definition and malloc function to define
Macro definition:
# Define N 10
Int a [N];
*/
2. The types of each element in the array are the same;
3. an array is an ordered array stored in the memory in order, and the memory address is from small to large; // The memory address is from small to large because there is only a accumulator In the CPU, there is no accumulators.
4. the array name is the address of the first element of the array, that is, the first address of the array. Of course, it can be understood that the array name is an address constant;
5. an array (such as int a [n]) is known. How to calculate the number of elements in an array (that is, to obtain the value of n) If you only know the array name and the number of elements in the array)
Answer: sizeof (a)/sizeof (a [0]);
/* The preceding sizeof (a) is the length of the entire array, and the following sizeof (a [0]) is the length of the first element in the array, because each element in the array has the same type, the Memory Length occupied by each element is the same, and the array must exist in a [0 */
6. Data Element initialization:
A. The number of elements initialized in the array cannot exceed the set length;
B. If the number of elements initialized by the array is not enough, the length will be later !! Auto-fill 0;
C.int a [] = {1, 2, 3, 4, 5}; such a statement is true. Although no length is specified, the elements initialized later are automatically filled in the memory, the length of the array is obtained during compilation. That is, the compiler divides the memory area according to the number of elements initialized by the array;
7. During compilation, the C language does not check whether the subscript of the array is out of bounds. However, during the running process, the kernel reports the "segmentation fault (core dumped)" segment error. // If an invalid memory area is operated during the running of the program, the operating system forcibly terminates the program to protect the data integrity in the memory, the "segment error" is reported because the subscript of the array is out of bounds, or the pointer does not point to a valid element...