In the code below, releasing memory from B also frees from A?
int* A = new int[4];
int *B = A;
delete[] B;
In the code below, releasing memory from B also frees from A?
int* A = new int[4];
int *B = A;
delete[] B;
Yes, because both pointers point to the same memory region.
Keep in mind that the pointer only indicates where your data is, delete B does not delete A, delete the content also pointed to by A.
After allocation: Afterthememoryisreleased:
Also note that A continues to point to the memory region, while B after delete points to an explicitly invalid region.