C qsort() with dynamic n by 2 multi-dimensional array

前端 未结 4 1780
情深已故
情深已故 2020-12-15 01:54

First, I defined a dynamic array with 2 columns and 10 row. The integer number is set to 10 here just for example.

int** array;
int number = 10;         


        
4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-15 02:13

    sizeof array[0] will be "2 * sizeof(int)", for this static array.

    int array[10][2];
    

    sizeof array[0] will be "sizeof(int*)", for this pointer-to-pointer. sizeof array[0][0] will be "sizeof(int)", for this pointer-to-pointer.

    int **array;
    

    So, First thing is you cannot use "qsort( array, number, sizeof array[0], compare );" in case of pointer-to-pointer implementation.

提交回复
热议问题