Tag: A string byte function memory release must be dynamically assigned to transfer otherwise
One or one-D arrays
-
- static int array[100]; An array of arrays is defined, and is not initialized with a group
- static int array[100] = {n}; The array of arrays is defined and initialized
- Dynamic int* array = new INT[100]; delete []array; Array with a length of 100 assigned
- Dynamic int* array = new int[100] (UP); delete []array; Initializes the first two elements for an array of length 100
Two or two-D arrays
-
- static int array[10][10]; An array is defined and is not initialized
- static int array[10][10] = {{n}, {2,2}}; Array initialized array[0][0,1] and array[1][0,1]
- dynamic int (*array) [n] = new Int[m][n]; delete []array;
- Dynamic int** array = new INT*[M]; for (i) array[i] = new Int[n]; for (i) delete []array[i]; delete []array; Multiple destruction
- Dynamic int* array = new Int[m][n]; delete []array; Arrays are stored by row
Three, multidimensional arrays
int* array = new INT[M][3][4]; Only the first dimension can be a variable, the other dimension must be a constant, or it will be an error
delete []array; Memory must be released, otherwise the memory will leak
Four, array as function parameter pass
-
- One-dimensional array delivery:
- void func (int* array);
- void func (int array[]);
- Two-dimensional array delivery:
- void func (int** array);
- void func (int (*array) [n]);
Array name as a function parameter, in the function body, it loses its own connotation, just a pointer, and in its loss of its connotation at the same time, it also lost its constant characteristics, can be self-increment, self-reduction and other operations, can be modified.
Five, character array
An array of type char is a character array of the Standing Committee, in which the last digit in the character array is the transfer character ' + ' (also a null character), which indicates that the string has ended. The string class is defined in C + + and the CString class is defined in Visual C + +.
Each character in a string occupies one byte, plus the last null character. Such as:
Char array[10] = "Cnblogs";
Although there are only 7 bytes, the string length is 8 bytes.
You can also not define string lengths, such as:
Char array[] = "Cnblogs";
C + + arrays