the initialization of an array space is to assign a value to each label address. Follow the label-by-process. If we need to assign a value to each memory, if there is an int a[100]; we're going to need to use the subscript - a int the spatial assignment of the type. This workload is very large, we think of the compiler to do some initialization operations, the initialization is the first assignment, the second assignment can no longer be assigned such a value.
int a[10]= space;
I need to give it a space to make a batch processing of the values in it, such as int a[10]={10,20,30}; A[1]=10,a[2]=20,a[3]=30,a[4]=...=a[9]=0 so actually the result of bulk memory copy, the result of unassigned is 0. Initialization is the same as the efficiency with which we assign each value. Bulk copies are limited to the first assignment only.
Note: The initialization of array space and the initialization of variables are different, especially in the embedded bare metal development, the initialization of the space often needs the auxiliary of the library function.
Char buf[10]={' A ', ' B ', ' C '}; The string C has an important property, and the string ends with a character ' \ s ' That represents the end of the string. Because we've defined the size of the string space by ten characters, but sometimes we're not using the ten bytes, and when We print it, Byte printing is also wrong, so in order to give the string an end to the flag, let other functions such as the printf function output to know its end.
Char buf[]= "ABC"; omitting the array size,C assigns the size to an array, which is three characters plus a trailing flag, and the size of the arrays is 4 .
Char buf[10]={"abc"};
Char buf[10]= "ABC"; bulk copy three characters to the space it allocates, end with ' + '
Char *p= "ABC"; space is allocated for three characters, and the pointer points to the first address of the string, which points to a constant string.
Buf[2]= ' E '; this is possible.
P[2]= ' E '; This is not possible,p is pointing to a constant area
The test code is as follows
we use this string as an argument to the printf function, which is actually returning the first address of the constant string, and here we print it as an integer, with a warning that it should be printed as an unsigned integer (the memory address is a positive integer type).
The operation results are as follows
You can see that an address is actually printed, which means that the double quotation marks are indeed an address, just as the character array we described earlier gets to its first address, and then copies it sequentially, but the character pointer gets its address store directly. These different operations are data type specific operations.
original link:http://www.maiziedu.com/wiki/c/space/
A detailed description of the initialization of the C-language array space