delete an element from an array in c++ code example

Example 1: remove a particular element from array

var colors = ["red","blue","car","green"];
var carIndex = colors.indexOf("car");//get  "car" index
//remove car from the colors array
colors.splice(carIndex, 1); // colors = ["red","blue","green"]

Example 2: Deleting an element from an array in PHP

$array = [0 => "a", 1 => "b", 2 => "c"];
unset($array[1]); //Key which you want to delete
/*
$array:
[
    [0] => a
    [2] => c
]
*/
//OR
$array = [0 => "a", 1 => "b", 2 => "c"];
array_splice($array, 1, 1);//Offset which you want to delet
/*
$array:
[
    [0] => a
    [1] => c
]
*/

Example 3: how to delete an element from an array

var array = [123, "yee", true];
array.pop(index);

Example 4: how to delete something in an array c++

delete myarray[elemen];

Example 5: 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;
}