- 论坛徽章:
- 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;
- }
复制代码 输出是这样的
[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了,
然后能解释一下每个输出的含义吗 |
|