I have been preparing for an interview recently, and I still have to make up on the basics. Sizeof (type) is a type of frequently encountered pen questions, in order to be able to remain unchanged, or to clarify the principle of sizeof the most convenient.
Note the following principles:
1. sizeof () is not a function, but an operand, that isKeywords(Most people are surprised at this point );
2. sizeof () returns the actual size of struct, arrays, and variables. However, for pointers, only the size of memory occupied by pointers can be returned, not the size of memory pointed to by pointers, that is, the size of the dynamically allocated memory space cannot be returned;
Exercise questions to consolidate what you have learned:
1 # Include <stdlib. h>
2 # Include <stdio. h>
3
4 Char * String = " Hello " ;
5 Int VaR = 100 ;
6 Int * Pint = NULL;
7 Int ** Ppint = NULL;
8 Int Array [ 100 ];
9
10 Int Array_func ( Char Para [ 100 ])
11 {
12 Return Sizeof (Para );
13 }
14
15 Int Malloc_func ( Void )
16 {
17 Int * P = NULL;
18 Return Sizeof (P = malloc ( 100 ));
19 }
20
21 Int Main ( Int Argc, Char * Argv [])
22 {
23 Char Para [ 100 ];
24
25 Printf ( " String size: % d \ n " , Sizeof ( String ));
26 Printf ( " VaR size: % d \ n " , Sizeof ( VaR ));
27 Printf ( " Pint size: % d \ n " , Sizeof (Pint ));
28 Printf ( " Ppint size: % d \ n " , Sizeof (Ppint ));
29 Printf ( " Array size: % d \ n " , Sizeof (Array ));
30
31 Printf ( " Array func size: % d \ n " , Array_func (para ));
32 Printf ( " Malloc func size: % d \ n " , Malloc_func ());
33
34 Return 1 ;
35 }
What is the running result? Think about it and then answer:>