Char A [] = {'s ', 'F', 'G', 'D', 'H '};
Char * B = "sfgdh ";
Char C [] = "sfgdh ";
Int a1 = 'a ';
Char d [6] = {'s ', 'F', 'G', 'D', 'H '};
Printf ("% d \ n", sizeof ());
Printf ("% d \ n", sizeof (B ));
Printf ("% d \ n", sizeof (c ));
Printf ("% d", sizeof (A1 ));
Printf ("% d", sizeof (d ));
Result:
5
4
6
4
6
Certificate -----------------------------------------------------------------------------------------------------------------------------------------------
Sizeof is the number of bytes occupied by the object in the memory.
Sizeof (a): calculates the total number of bytes in array A. The total number of bytes must be determined by the array type and the number of array elements. The number of elements is required. sizeof (a)/sizeof (char) indicates the number of elements. Because char occupies one byte, the result is: 5. Remember that the array name is the first address of the first element of the array. It is a constant and a cannot be used for value assignment.
Sizeof (B): B is a pointer variable, that is, the variable that stores the address. No matter what type of pointer variable, sizeof () is the memory size occupied by the address, it is 4 bytes.
The array element in the C array is 6, because the last one is '\ 0 '.
The size of the space required by the object A1 obtained by sizeof (A1) in the memory. The Int type requires 4 bytes, so it is 4.
Sizeof (d) is a description. The number of arrays is determined by the value given by brackets. If not, it is determined by the number of braces.