void create_arr()
{
int rows = 2;
int columns = 4;
int** matrix = (int**)malloc(rows * sizeof(int*));
for (int i = 0; i<rows; i++)
{
matrix[i] = (int*)malloc(columns * sizeof(int));
}
for (int i = 0; i < rows; ++i)
{
for (int j = 0; j < columns; ++j)
{
printf("&(matrix[%d][%d]) : 0x%p\n", i, j, &(matrix[i][j]));
}
}
}
void create_arr_sort()
{
int rows = 2;
int columns = 4;
int** matrix = (int**)malloc(rows * sizeof(int*));
matrix[0] = (int*)malloc(sizeof(int) * rows * columns);
for (int i = 0; i < rows; ++i)
{
matrix[i] = matrix[0] + i * columns;
}
for (int i = 0; i < rows; ++i)
{
for (int j = 0; j < columns; ++j)
{
printf("&(matrix[%d][%d]) : 0x%p\n", i, j, &(matrix[i][j]));
}
}
}
void create_arr_sort2()
{
int rows = 2;
int colums = 4;
int* matrix = (int*)malloc(sizeof(int) * rows * colums);
for (int i = 0; i < rows; ++i)
{
for (int j = 0; j < colums; ++j)
{
printf("0x%p\n", matrix + (i * colums) + j);
}
}
}
```
原文:https://www.cnblogs.com/s3320/p/12535386.html