代码:
int *Array[8];
Array[0] = (int *) malloc(sizeof(int) * 5);
printf("%d" , sizeof(Array)/sizeof(int)); // Result = 8 : True
printf("%d" , sizeof(Array[0])/sizeof(int)); // Result = 1 : False
如何获得数组 [0] 的长度为 5?
最佳答案
你不能。
C 中的动态数组不携带它们的长度信息。因此,您需要在编写代码时记住它分配了长度为 5 的内容。
关于c - 在 C 中获取锯齿状数组的长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9549499/