我正在做这样的事情;
int main()
{
int *b[2], j;
for (j = 0; j < 2; j++)
{
b[j] = (int *)malloc(12 * sizeof(int));
}
return 0;
}
请告诉我这条指令的真正含义是什么?如何将此指针数组传递给函数以访问 *(B[0]+1),*(B[1]+1)
等值?
最佳答案
int main(void)
{
int *b[2], j; // initialization of an array of pointers to integers (size = 2)
for (j = 0; j < 2; j++) // for each of the pointers
{
b[j] = malloc(12 * sizeof (int)); // allocate some space = 12 times size of integer in bytes (usually 4)
}
return 0;
}
如果你想将此数组传递给函数,只需传递 b
foo(b);
关于c - 理解指针数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59735011/