What happens when you copy a pointer obtained from new, and then delete?

78 Views Asked by At

This is a problem based on C++11.

What‘s happened when I delete a dynamic array by another pointer? Has this dynamic array been deleted actually?

    int* a = new int[NUM01];
    int* a1 = a;

    for (int i = 0; i < NUM01; i++) {
        a1[i] = 0;
    }

    delete[] a1;    //What's happened?

I try to observe a[0].

    cout << a[0] << endl;

    delete[] a1;

    cout << a[0] << endl;

The result is: 0 -572662307

What's the real?

0

There are 0 best solutions below