Tag: Type causes character array undefined span reference function ptr particularity
Array
Arrays are containers that hold objects of the same type. These objects themselves have no name and need to be accessed through their location. The size of the array is determined to be constant, and you cannot add elements to the array arbitrarily.
An array is a composite type that is declared as a[d],a an array name, and B is an array dimension (which describes the number of elements in a set).
Array initialization
By default, the elements of an array are initialized by default. An array of a built-in type is defined inside the function, so the default initialization order array contains undefined values. An array of built-in types is defined outside the function body, so the default initialization order array contains a value of 0.
Explicitly initializing an array element
Constunsigned sz =3;intIa1[sz] = {0,1,2};//sz is constantintA2[] = {0,1,2};//the array latitude can be empty. Determines the array dimension during compilation based on the number of array initial valuesinta3[5] = {0,1,2};//equivalent to a3[] = {0, 1, 2, 0, 0};stringa4[3] = {"Hi","Bye"};//equivalent to a4[] = {"Hi", "Bye", ""};inta5[2] = {0,1,2};//error, the initial value exceeds the dimension of the arrayThe particularity of character array
When initializing character arrays with string literals, it is important to note that there is also a null character at the end of the string literal, which is copied to the character array as the other ego of the string.
CharA1[] = {'C','+','+'};//list initialization, no null charactersCharA2[] = {'C','+','+',' /'};//explicit NULL charactersCharA3[] ="C + +";//automatically adds a null character that represents the end of a stringConst Chara4[6] ="Daniel";//error. Because the string literal has a null character at the end, it causes the array space to be insufficientComplex array declarations (difficulty)
int *ptrs[]; // Ptrs is an array that contains 10 integer pointers int (*parray) [ten] = &arr; // Parray points to an array containing 10 integers int (&ARRREF) [ten] = arr; // Arrref A reference to an array of 10 integers int * (&arry) [ten] = ptrs; // Arry is a reference to an array that contains 10 pointers
Pointers and Arrays
[C + +] Array