Answers for "how to delete an element from array in cpp"

C++
0

none

// 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 January-01-1970
0

how to delete an element from array in cpp

/ 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 October-26-2021

Code answers related to "how to delete an element from array in cpp"

Browse Popular Code Answers by Language