I'm attempting to create a dynamic Matrix with functions, but first I decided to segment the assignment so that I know everything works as it should. But the creation is not working.
I tried moving the parentheses, using different values, but it always crashes when i=2
int rows=4;
int columns=4;
int cont=1;
int ** Mat;
Mat=(int**)malloc(rows*columns*sizeof(int));
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
{
printf("%d",i);
*(*(Mat+i)+j)=cont++;
}
}
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
{
printf("%2d ", *(*(Mat+i)+j) ); /* a[i][j] */
}
printf("\n");
}
I don't get any compilation errors, I would expect this 1234 5678 9101112 13141516