- 論壇徽章:
- 0
|
- #include "stdio.h"
- #include "malloc.h"
- #include "assert.h"
- #include "stdarg.h"
- #include "stdint.h"
- #include "time.h"
- #include "limits.h"
- #include "string.h"
- #include "unistd.h"
- #include "stddef.h"
- #include "errno.h"
- typedef struct { /* type of structure for an element of a list */
- char *ptr; /* pointer to the region */
- int size; /* size of the effective region */
- } TCLISTDATUM;
- typedef struct { /* type of structure for an array list */
- TCLISTDATUM *array; /* array of data */
- int anum; /* number of the elements of the array */
- int start; /* start index of used elements */
- int num; /* number of used elements */
- } TCLIST;
- int main()
- {
- TCLIST *list = (TCLIST *)malloc(sizeof(*list));
- printf("%d\n", sizeof(TCLIST));
- printf("%d\n", sizeof(*list));
- printf("%d\n", sizeof(list));
- printf("\n", sizeof(list));
- list->anum = 1;
- printf("%d\n", sizeof(*list->array));
- printf("%d\n", sizeof(TCLISTDATUM));
- printf("%d\n", sizeof(list->array));
- printf("%d\n", sizeof(list->array[0]));
- printf("%d\n", sizeof(list->array[1]));
- printf("%d\n", sizeof(list->array[2]));
- list->array = (TCLISTDATUM *)malloc(sizeof(TCLISTDATUM) * list->anum);
- list->start = 0;
- list->num = 0;
- }
復(fù)制代碼 輸出是這樣的
[root@localhost www]# ./test
24
24
8
16
16
8
16
16
16
請問 printf("%d\n", sizeof(list));和 printf("%d\n", sizeof(list->array));怎么變成8了,
然后能解釋一下每個(gè)輸出的含義嗎 |
|