此问题在此处已有答案:
How do you get the size of array that is passed into the function?(8个答案)
How to get array size within function?(1个答案)
Calculate Length of Array in C by Using Function(9个答案)
昨天就关门了。
如何在C语言中创建一个函数来获取数组的大小?函数和数组不在同一个作用域。例如:
int func(int arr[]);
int main(){
int arr[5];
}
个字符
上述函数的问题是,它将arr视为指针,因此它具有指针的大小
1条答案
按热度按时间f1tvaqid1#
简单地将数组长度沿着传递给参数中的数组指针,这是很常见的
字符串
或者在应用程序中为数组创建更复杂的结构:
型
你也可以使用我的实现:https://gist.github.com/arianito/57e668790b723a6e6649d4535e9dcaae