<分区>
Possible Duplicate:
length of array in function argument
我的数组大小是5。例如:
arrCustId[5]
我如何知道我的数组中已经存在多少个客户 ID? 总之如何找到数组的长度?
<分区>
Possible Duplicate:
length of array in function argument
我的数组大小是5。例如:
arrCustId[5]
我如何知道我的数组中已经存在多少个客户 ID? 总之如何找到数组的长度?
最佳答案
如果数组是静态分配的,使用sizeof(array)/sizeof(array[0])
但是,如果它是动态分配的,不幸的是你运气不好,因为这个技巧总是返回 sizeof(pointer_type)/sizeof(array[0])
(在 32 上是 4带有 char*s 的位系统)您可以 a) 保持 #define(或 const)常量,或者 b) 保持一个变量。
关于c - 如何找到数组中存在的项目的长度/数量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5604838/