1// Delete pointer
2int* ptr1 = new int;
3delete ptr1;
4
5// Delete array
6int* array = new int[10];
7delete[] array;
1// operator delete[] example
2// an advanced example :
3#include <iostream>
4
5using namespace std;
6
7struct MyClass {
8 MyClass() {cout <<"MyClass constructed\n";}
9 ~MyClass() {cout <<"MyClass destroyed\n";}
10};
11
12int main () {
13 MyClass * pt;
14
15 pt = new MyClass[3];
16 delete[] pt;
17
18 return 0;
19}
20//simple exmaple :
21int main () {
22 int * pt;
23
24 pt = new int [3];
25 delete[] pt;
26
27 return 0;
28}