我有5个数组和一个指针数组,我需要知道指针数组(不是sizeof)中每个数组的长度是多少。 我该怎么做?如何知道指针数组中指针的长度是多少?
int arr1[] = { 3, 9, 6, 7 };
int arr2[] = { 2, 5, 5 };
int arr3[] = { 0 };
int arr4[] = { 1, 6 };
int arr5[] = { 4, 5, 6, 2, 1 };
int* arr6[] = { arr1, arr2, arr3, arr4, arr5 };
基于这个家庭作业的所有以前的版本,是不是在数组本身的答案? –
恐怕你不能。一旦转换为'int *',它们的大小将不可避免地丢失给编译器。在运行时,一个int数组没有大小的概念。您应该:将其大小记录在其他地方,或者隐式编码(例如,最后一个元素应该总是指定的,否则不使用,常量,比如'0'或'-1')。 – rslemos
不完全重复,但这个问题似乎有更好的理解这个作业http://stackoverflow.com/questions/43191792/sorting-5-arrays-in-one-function –