#include <iostream>
#include <string>
using namespace std;
void print(string data[], int size) {
cout << "Print array" << endl;
for (int i=0; i<size; i++) {
cout << data[i] << ", ";
}
cout << endl;
}
int main(int argc, char** argv) {
string arr1[] = {"Apple", "Banana", "Coconut", "Durian"};
string *arr2 = new string[6];
arr2[4] = "Eggplant";
arr2[5] = "AppleBanana";
std::copy(std::begin(arr1), std::end(arr1), arr2);
print(arr2, 6);
delete[] arr2;
print(arr2, 6);
return 0;
}
I was wondering why delete[] arr2;
only free up the arr2[0] because after I print it again only the first element in arr2 is freed but the rest still got the elements
I don't quite understand the free()/delete yet so it would be nice if someone also help explain it. I have been asking professor about it and I'm still confused as to why freeing up arr2 still got elements in its