Answers for "delete an array c++"

C++
7

c++ delet from memory

// Delete pointer
int* ptr1 = new int;
delete ptr1;

// Delete array
int* array = new int[10];
delete[] array;
Posted by: Guest on March-09-2020
1

delete an array c++

// operator delete[] example
// an advanced example :
#include <iostream> 

using namespace std;

struct MyClass {
  MyClass() {cout <<"MyClass constructed\n";}
  ~MyClass() {cout <<"MyClass destroyed\n";}
};

int main () {
  MyClass * pt;

  pt = new MyClass[3];
  delete[] pt;

  return 0;
}
//simple exmaple :
int main () {
  int * pt;

  pt = new int [3];
  delete[] pt;

  return 0;
}
Posted by: Guest on December-21-2020

Code answers related to "delete an array c++"

Browse Popular Code Answers by Language