There are a couple of issues here. It's not completely clear to me what your goal is, but it looks like you want to deal with a 2 dimensional array where the 2nd dimension has different length entries.
int* arr1[3] = { 2, 5, 8 };
There you create an array containing pointers. You're initializing the elements with numbers, but those are pointers -- the entries point to the memory address denoted by the number. I.e. the first element points to memory address 2 -- is that really intended? If you want to store numbers you need to use a simple array here.
int** bigArr[5] = {*arr1, *arr2, *arr3, *arr4, *arr5};
Here you assigne the value of arr1 and so on to the elements of bigArr. However, since you dereference arr1 you don't get a pointer to the array. Instead you get the value of the first element (*arr1 is basically the same as arr1[0]). So now bigArr stores int** values, which are simply the first element of the subarray. No pointer to the subarrays is stored. You can access array elements via pointer or array access, and that's basically what's going wrong here.
Speaking about pointers in general: The following two lines behave identical:
int a = arr1[1];
int b = *(arr1 + 1);
as well as you can get a pointer to an array in two different ways. In the end both pointers point to the first element of the array:
int array[] = {1, 2, 3};
int *ptr1 = array;
int *ptr2 = &array[0];
Last, C doesn't store the length of an array -- you need to know this.
I'm assuming you want to store a data structure like this:
[
[ 2, 5, 8 ],
[ 1, 7 ],
[ 5, 1, 8, 3, 7, 12 ],
[ 3, 9, 4, 29 ],
[ 4, 11, 17, 23, 25 ]
]
To do this you don't need double pointers. Also, you need to store the length of the subarray. An approach to this could be to use an array of struct.
struct row {
int* data;
int length;
};
int arr1[3] = { 2, 5, 8 };
int arr2[2] = { 1, 7 };
// ...
struct row r1 = {arr1, 3};
struct row r2 = {arr2, 2};
// ...
struct row *bigArr[] = {r1, r2, ...};
Now sortNumber changes to
void sortNumber(struct row* r)
{
for(int i = 0; i < r->length; i++) {
printf("%i ", r->data[i]);
}
printf("\n");
}
*arr1is of typeint *, and the same is true of the other expressions used to initializebigArr. If you used&arr1[0]instead (type "pointer tointpointer, orint **), then it would be fine. Aside from that, OldProgrammer is correct in that you need a loop. However, here's a question related to the loop idea: how do you know where the array passed tosortNumberends? There is noitemCountparameter, andbigArrdoesn't end with any sort of sentinel value such as aNULLpointer.array.lengthproperty like you find in many other languages. As such, you need to define cleary define anitemCount(or use a sentinel value, but that can get messy when you're dealing with integers). You may want to consider using something like this:struct iArray_s{ int *arr; int itemCount; }This would create a struct that you can store your integer array in as well as a variable that can specify how many members the array contains.