例子:
file1.c file2.c
int a[]={1,2,3} extern int a[];
在文件file1.c中定义一数组,在文件file2.c中extern声明,但file2.c中调用sizeof()得不到数组的大小
因为未指定大小的extern数组是不完全类型,不能对他使用sizeof,因为sizeof在编译时发挥作用
三种解决方案:

本文探讨了在C语言中,当一个数组被extern声明时,如何解决无法通过sizeof获取其大小的问题。介绍了extern关键字的用途,并提供了三种可行的解决方案。
例子:
file1.c file2.c
int a[]={1,2,3} extern int a[];
在文件file1.c中定义一数组,在文件file2.c中extern声明,但file2.c中调用sizeof()得不到数组的大小
因为未指定大小的extern数组是不完全类型,不能对他使用sizeof,因为sizeof在编译时发挥作用
三种解决方案:


被折叠的 条评论
为什么被折叠?
