Hello I’m in an intermediary C class right now and this thought just came to my mind:
int multi[3][4]; // const multidimensional array
int* ptr = *multi; // ptr is a pointer variable that hold the address of multi const array
So, what is faster/smaller/optimized for access a multidimensional array position?
This:
multi[3][1]; // index the value position
or
*(*(multi+2)+1); // pointer to the position on the array
or (UPDATED)
ptr += 9; // pointer arithmetic using auxiliary pointer
Since “multi” is an const array the compiler should “know” already the localization of the element position, in case of using an variable pointer pointing to that array that could take more processing time, on the other hand could be faster when searching for the item that I want to display. What is the faster/smaller/optimized approach?
Thank you in advance.
They’re all compiled in the same way,
*(pointer_to_first_element + x + y).