I came across this code while looking for jagged arrays in C. I am finding it difficult to understand the need for typecasting the calloc function since calloc() and malloc() return pointers.
int rowNum,colNum,i,j;
int** table;
scanf("%d",&rowNum);
Why are we using a pointer to a pointer and what does the line below return?
table = (int**)calloc(rowNum+1,sizeof(int*));
for(i=0;i<rowNum;i++)
{
printf("The size of %d row",i+1);
scanf("%d",&colNum);
table[i] = (int*) calloc(colNum+1,sizeof(int));
What's happening in the above line? Is the pointer pointing to the base element of the ith row?
for(j=1;j<=colNum;j++)
{
//reading the elements in the row
scanf("%d",&table[i][j]);.
}
table[i][0] = colNum;
printf("The size of row [%d]= %d",i+1,table[i][0]);
}
What is table pointing to here?