[CareerCup] 13.10 Allocate a 2D Array 分配一个二维数组 - Grandyang - 博客园
13.10 Write a function in C called my2DAlloc which allocates a two-dimensional array. Minimize the number of calls to malloc and make sure that the memory is accessible by the notation arr[i][j].
这道题让我们写个C语言函数my2DAlloc用来给一个二维数组分配内存,并且让我们尽可能的少调用malloc函数。一个二维数组实际是数组的数组,我们用指针来表示数组,用双指针来表示二维数组。我们首先建立一个一维数组,对于每个位置,再建立一个一维数组,这样我们就得到了一个二维数组,参见如下代码
Read full article from [CareerCup] 13.10 Allocate a 2D Array 分配一个二维数组 - Grandyang - 博客园
No comments:
Post a Comment