I know it's very basic but I MUST understand the concept, why it doesn't work?
void printMat(int arr[N][N], int n)
{
int i, j;
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
if (i < j)
{
arr[i][j] = 0;
}
{
arr[i][j] = i+j+2;
}
}
int** triDown(int arr[N][N], int n)
{
int i, j, **a;
for(i = 0; i < n; i++)
{
*(a+i) = (int*)malloc(sizeof(int)*(i+1));
}
for(i=0;i<n;i++)
for(j=0;j<i+1;j++)
{
a[i][j] = arr[i][j];
}
return a;
}
void main()
{
int *arr[N],**NewMat;
printMat(arr,N);
NewMat = triDown(arr,N);
}
I'm having a really hard time trying to understand the pointer-to-pointer thing when it comes to functions and dynamic allocations.
What should've been done in NewMat
func?