如果我的函数中有一个参数 int **a
我想知道 a = (int **)malloc(sizeof(a)*(length)
和 *a = (int *)malloc(sizeof(a)* 有什么区别(长度)
我上周发现了 malloc,所以我还不了解所有内容。
谢谢 !
最佳答案
malloc
只返回一个 void *
指针,仅此而已。
a
是指向指针的指针。
等号的右边在这里并不重要,所以不要管右边。现在我们得到了:
// 1st code fragment
int **a1;
// Asign a null pointer to a1, now a1 is a NULL pointer
a1 = (int **)NULL;
// 2rd code fragment
int **a2;
// Asign a null pointer to the pointer pointed by a2.
// Here may crash actually, because a2 is not initialized yet.
*a2 = (int *)NULL;
关于c - 带有 int 的 Malloc **,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51949703/