No object is assigned to address 0. Therefore, 0 is treated as a pointer text volume, indicating that a pointer did not point to any object at the time. In C, a macro null is commonly used to represent 0 pointers. Due to the type check rules tightened by C ++, using normal 0 instead of the null macro recommended by some people causes fewer problems.
The number of array elements, that is, the bounds of the array, must be a constant expression. If you need to change the bounds, you can use vector. For example:
Void F (int I)
{
Int V1 [I]; // error. The array size must be a constant expression.
Vector <int> V2 (I); // Yes
}
Comma is a sequence operator and cannot appear in constant expressions. For example:
Int bad [5, 2]; // error. The comma does not allow the entry to be in a constant expression.
If the size is specified, it is an error that the array has given redundant elements in the initialization list. For example:
Char V3 [2] = {'A', 'B', 0}; // error, too many initial statements
Char V4 [3] = {'A', 'B', 0}; // Yes
If there are too few elements in the initial expression list, the remaining elements are set to 0. For example:
Int V5 [8] = {1, 2, 3, 4 };
Equivalent
Int V5 [8] = {1, 2, 3, 4, 0, 0, 0 };
Char P [] = "ABC" "def"; equivalent to Char P [] = "abcdef ";
Int V [] = {1, 2, 3, 4 };
Int * P3 = & V [4]; // point to a position after the last element
Obtain the pointer at an element position after an array ends, which can be ensured. Of course, this pointer does not actually point to an element in the array, so it cannot be used to read or write
The constant must be initialized. For example:
Const int model = 90; // The model is a constant.
Const int X; // error, not initialized
Int my_f (INT );
Const int C3 = my_f (3); // feasible, the compiler does not know the value of C3
Int A = 3;
Const int * P = & A; // Yes
* P = 10; // error, * P is const int
Int & n = 2 // error, left value required
Const Int & n = 2; // Yes
The void pointer cannot be operated directly. For example:
Int * P;
Void * Pv = P; // Yes
* PV; // Error
PV ++ // Error