亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 1684 | 回復(fù): 1
打印 上一主題 下一主題

[C] sizeof參數(shù)問題 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2014-08-20 19:12 |只看該作者 |倒序?yàn)g覽
  1. #include "stdio.h"
  2. #include "malloc.h"
  3. #include "assert.h"
  4. #include "stdarg.h"
  5. #include "stdint.h"
  6. #include "time.h"
  7. #include "limits.h"
  8. #include "string.h"
  9. #include "unistd.h"
  10. #include "stddef.h"
  11. #include "errno.h"


  12. typedef struct {                         /* type of structure for an element of a list */
  13.   char *ptr;                             /* pointer to the region */
  14.   int size;                              /* size of the effective region */
  15. } TCLISTDATUM;

  16. typedef struct {                         /* type of structure for an array list */
  17.   TCLISTDATUM *array;                    /* array of data */
  18.   int anum;                              /* number of the elements of the array */
  19.   int start;                             /* start index of used elements */
  20.   int num;                               /* number of used elements */
  21. } TCLIST;

  22. int main()
  23. {

  24.   TCLIST *list = (TCLIST *)malloc(sizeof(*list));
  25.   printf("%d\n", sizeof(TCLIST));
  26.   printf("%d\n", sizeof(*list));
  27.   printf("%d\n", sizeof(list));
  28.   printf("\n", sizeof(list));
  29.   list->anum = 1;
  30.   printf("%d\n", sizeof(*list->array));
  31.   printf("%d\n", sizeof(TCLISTDATUM));
  32.   printf("%d\n", sizeof(list->array));
  33.   printf("%d\n", sizeof(list->array[0]));
  34.   printf("%d\n", sizeof(list->array[1]));
  35.   printf("%d\n", sizeof(list->array[2]));
  36.   list->array = (TCLISTDATUM *)malloc(sizeof(TCLISTDATUM) * list->anum);
  37.   list->start = 0;
  38.   list->num = 0;
  39. }
復(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è)輸出的含義嗎

論壇徽章:
0
2 [報(bào)告]
發(fā)表于 2014-08-20 19:36 |只看該作者
list是個(gè)指針,這里顯示8B,說明這個(gè)應(yīng)該是64位的環(huán)境,那么sizeof(list->array)也就好理解了,另外還要注意的這里是8字節(jié)對齊,分析一下,不難理解。
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP