I have this code:
int *array_ptr{nullptr};
array_ptr = new int[10]; // allocate array on the heap
for(int i=0; i<10; i++){
array_ptr[i] = i;
std::cout<<array_ptr[i]<<std::endl;
}
delete [] array_ptr; // deletes allocated space
To my understanding, int *array_ptr
displays the actual value, whereas int array_ptr
with no dereference operator displays the address in memory.
So, how come array_ptr[i]
displays 0 1 2 3 4 ... 10, instead of displaying address 1000, 1004, 1008...etc. (address nr made up).
Aucun commentaire:
Enregistrer un commentaire