int* myPointer = new int[100];
// ...
int firstValue = *(myPointer + 0);
int secondValue = myPointer[1];
Is there any functional difference betwe
There is no difference between
*(array+10); //and
array[10];
but guess what? since +
is commutative
*(10 + array); //is all the same
10[array]; //! it's true try it !
No, they are functionally equivalent.
First, index
is scaled up to the type size then added to the myPointer
base, then the value is extracted from that memory location.
The "better practice" is the more readable one, which is usually, but not necessarily always, the myPointer[index]
variant.
That's because you're usually interested in an element of the array, not the memory location to dereference.