Yes, the elements are guaranteed to be located in the communicative memory (regardless of their type). When you call new[] , you get an array, and in fact the only way to access the elements is through pointer arithmetic.
Consider what arr[i] means:
arr[i]
actually only a short form
*( ( arr ) + (i) )
A bizarre side effect of this is that for arr array and index i
i[arr]
just like arr[i] (although you would only write this if you want to confuse your colleagues).
However, note that [] can be overloaded, in which case it can do whatever the implementation chooses. However, an array allocated with new[] , which has an overloaded oeprator[] , will have its elements in sequential memory.
user463035818
source share