gpt4 book ai didi

c - C中的外部数组没有大小

转载 作者:行者123 更新时间:2023-11-30 18:41:29 25 4
gpt4 key购买 nike

未编译:

int a[];

编译:

extern int a[];

未编译(找不到 sizeof):

printf("%lu\n", sizeof(a)/sizeof(int));

所以问题:

  1. 为什么可以创建外部数组。
  2. 分配了多少内存?

问题原因 - http://users.dcc.uchile.cl/~rbaeza/handbook/algs/4/444.sort.c

extern int maxfiles, maxruns[], actruns[];
for (i=0; i<=maxfiles; i++) maxruns[i] = actruns[i] = 0;

正确吗?

最佳答案

1.) 您尚未创建 extern 数组。相反,您已经声明了一个数组存在,并且它是在其他地方(外部)创建的。在它创建的地方,它确实有特定的大小。

2.) 因为您还没有创建数组,所以没有为其分配大小。 (参见#1)。相反,该数组是在另一个文件/模块/组件(外部)中创建的,这是该数组存在的声明,并且可以在此处访问。

关于c - C中的外部数组没有大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21266777/

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