The title is the question.
I still don't quite understand the behavior of dynamically allocated storages.
#include <utility>
int main() {
// Case 1:
volatile char *c1 = new char; // I'm gonna make these volatile, so the compiler won't change the code.
volatile char *d1 = c1;
delete d1;
// Case 2:
volatile char *c2 = new char[4];
volatile char *d2 = c2;
delete []d2;
// Case 3:
volatile char *c3 = new char;
volatile char *d3 = std::move(c3);
delete d3;
// Case 4:
volatile char *c4 = new char[4];
delete c4++;
delete []c4;
// Case 5:
volatile char *c5 = new char[4];
for (int i = 0; i < 4; ++i)
delete c5++;
return 0;
}
Will the memory leak in each situation?