gpt4 book ai didi

C 数组初始化大小(以字节为单位)

转载 作者:太空宇宙 更新时间:2023-11-04 05:08:12 24 4
gpt4 key购买 nike

我预计以下数组初始化的大小为 32。1 个字节的字符,列表中的每个项目 2 个字节,16 个项目....= 32。但是它是 128 个字节。为什么?

char* cmds[] = {"AQ", "BD", "LS", "TW", "AS", "CP", "TR", "CO", "BF", "MS", "SR", "TL", "WT", "PM", "TE", "TC"};
printf("%li\n", sizeof(cmds));
//result is 128
//size of list is 16
//8 bytes per item in the list
//why?

最佳答案

那是因为你有一个指向 char 的指针数组。每个指针都是 8 字节(在 x64 上),因此 16 个指针 x 8 字节 = 128 字节。

关于C 数组初始化大小(以字节为单位),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5531960/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com