Three minutes to understand the C language sizeof
I. Concepts
Sizeof is a single object operator, which is the same as a ++ operator. Outputs the storage size of the operation object in bytes.
Ii. Usage a. operation data type
For example, sizeof (int), the length of the output int type in the memory, depending on the specific environment, the local output is 4.
B. Operation Variables
For example, char a [6]; printf ("% d \ n", sizeof (a). Because the char array length has been defined, the output value is 6.
Iii. FAQs
Note the following examples:
Example 1:
Int testSizeOf (char x []) {return sizeof (x);} int main (int argc, char * argv []) {char y [6]; int temp = testSizeOf (y); printf ("% d \ n", temp );}
The output result here is no longer 6, because in the testSizeOf function, a pointer is actually passed in, so here sizeof actually takes the number of bytes of the pointer, so the result is 4.
Example 2:
Int main (int argc, char * argv []) {printf ("% d \ n", sizeof ("0123456789 "));}
Here, the output result is 11, because in the language, Ten Characters and the ending character "\ 0" are considered here ".