I know that If i define an array like
int a [10];
I can use a pointer notation, to access it's address using a+<corresponding_item_in_array>
and it's value using, *(a+<corresponding_item_in_array>)
.
Now I wanted to reverse things, I used malloc
to allocate a memory to a integer pointer, and tried to represent the pointer in subscript notation but it didn't work
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
I may have used an pointer expression using Storage Mapping, but ain't the simpler method available? and Why?