I have an array that has arrays in each cell. For example, a large array is called arr:
int a[3] = {3, 2, 1};
int b[2] = {2, 1};
int *arr[2] = {a, b}
Now the problem is that if I want to print small arrs inside a large array.
Here is my code:
#include <stdio.h>
void printArr(int arr [], int n)
{
for (int i = 0 ; i < n ; i++)
{
printf("%d ", *(arr + i));
}
printf("\n");
}
int main()
{
int a[5] = {1, 8, 4, 2, 0};
int b[3] = {1, 4, 2};
int *arr [2] = {a, b};
int n = 0;
for (int i = 0 ; i < 2 ; i++)
{
printArr(*(arr + i), n);
}
}
The result should be something like this:
1 8 4 2 0
1 4 2
But I canβt get the size of each array, since it sizeof(*(arr + i)gives me 4, this is the size of the pointer (array name), not the whole array. So what can I do?
Thank!
source
share