Because here when you resize
int main() {
// Initialize variable size
int size = 5;
// Create Array
int * Arr = new int[size];
// Fill elements of an array
for (int i = 0; i < size; i++) {
Arr[i] = i;
}
// Call printArray function
printArray(Arr, size);
// Create new array
int * ResizeArray = new int[size + 2];
// Copy elements in new arary
for (int i = 0; i < size; i++) {
ResizeArray[i] = Arr[i];
}
// Delete old array
delete[] Arr;
// Pointer Array will point to ResizeArray
Arr = ResizeArray;
// Store new values
Arr[size] = 90;
Arr[size + 1] = 100;
// Call printArray function
printArray(Arr, size + 2);
}
You are really just making another array and changing the pointer of the first array.
Blockquote
Course: Learn C++: The Complete Course for Beginners - Learn Interactively
Lesson: Dynamic Arrays - Learn C++: The Complete Course for Beginners