我知道如果我定义一个像
int a [10];
我可以使用指针表示法来访问它的地址 usinga+<corresponding_item_in_array>
和它的值 using, *(a+<corresponding_item_in_array>)
。
现在我想反转事情,我曾经malloc
为整数指针分配内存,并尝试用下标表示法表示指针,但它不起作用
int *output_array;
output_array = (int *) (malloc(2*2*2*sizeof(int))); //i.e, space for 3d array
output_array[0][0][1] = 25;
// ^ produces error: subscripted value is neither array nor pointer
我可能使用了存储映射的指针表达式,但不是更简单的方法可用吗?为什么?