People who are used to. net and java are not used to using arrays of C/C ++. Arrays and pointers in C/C ++ are equivalent, but they are slightly written.
1. Parameters
For example, an array is used as an input parameter in two ways:
[Cpp]
Int FindMax1 (int * Array );
Int FindMax2 (int Array []);
Compilation is successful, and the semantics is the same.
However, in array initialization:
[Html]
// Invalid int * Array1 = {0, 1, 2, 3 };
Int Array [] = {0, 1, 2, 3}; // pass
Note that the order in which * and [] are combined with int is different.
2. Parameters
In addition, initializing an array in the form of int ArrayName [] can improve the efficiency of array variable initialization.
[Cpp]
Int Array1 [10] = {0}; // initialize the entire array member element to 0;
Char Array2 [] = {'A', 'B', 'C', 0}; // The size is not specified when the array is defined. When the array is initialized, the list is initialized, the array size is determined by the number of list elements during initialization. The array length is 4.
Int Array3 [8] = {1, 2, 3, 4}; // when the declared length of the array is greater than the length of the list element, the remaining element is initialized to 0, equivalent to int v5 [8] = {1, 2, 3, 4, 0, 0, 0 };
3, sizeof ()
Sizeof (int *), the number of bytes of the array pointer. The 32-bit system is 4;
Int Array1 [10] = {0 };
Sizeof (Array1), the actual memory space occupied by the array, here is 4*10 = 40;
Summary:
Int * Array1 indicates the pointer, while int Array1 [] indicates the array.
In the column from bestwolf1983