Ok, so I have two pointers, one initialising new array:
int * array = new int [5];
int * ptr = &array[0]; // or "= array", is this the same?
Now let's assign some value
array[0] = 12;
Now check if they point the same adress and value
cout << "Adress under array: "<< array << " Value under array: "<< array[0] <<
" Adress under ptr: "<< ptr << " Value under ptr: " << *ptr;
Output shows the same adresses, and 12 two times. Now let's delete array:
delete [] array;
Now there is my question, this:
cout << array;
Output different address than before. Additionaly
cout << *ptr;
does not output 12, so the value in the old array[0] changed.
Then, where the pointer points after deleting array []array
?
The other question, is array pointer to array, or just pointer for int?
I know that int *ptr[x]
will be a pointer to array of x integers, but i do not use square brackets on the left side here int * array = new int [5]
so is array
the pointer to the first element of the array?