#include <stdio.h>
#include <stdlib.h>
typedef int * pinax;
int main()
{
pinax *A;
int size,i,j;
int *cols;
printf ("How many sets of numbers: ");
scanf ("%d",&size);
cols = (int*) malloc (size*sizeof(int));
A = (pinax *) malloc (size * sizeof(pinax));
//Above part i cant understand
for (i=0;i<size;i++)
{
printf ("How many numbers in set %d: ",i+1);
scanf("%d",&cols[i]);
A[i] = malloc (cols[i]*sizeof(int));
printf ("Give %d numbers seperated by space or newline: ",cols[i]);
for (j=0;j<cols[i];j++)
scanf ("%d",&A[i][j]);
}
for (i=0;i<size;i++) // First dimension is not stable
{
for (j=0;j<cols[i];j++) // Second dimension is not stable
printf ("%d ",A[i][j]);
printf ("\n");
}
return 0;
}
This is a come in my uni's notes that basically creates a dynamic 2D array.I have trouble understanding how it works above the comment i came.The 2 last comments are my prof's and i really cant understand why the dimension in the last 2 for loops is stable.Can someone explain me?