Allocating a pointer, using it, and then freeing it. - C++ Operator

C++ examples for Operator:delete

Description

Allocating a pointer, using it, and then freeing it.

Demo Code

#include <iostream>
#include <string>
using namespace std;

int main()/*ww w .  ja  v a  2s .  c  om*/
{
  string *phrase = new string("this is a test!");
  cout << *phrase << endl;

  (*phrase)[20] = 'r';

  phrase->replace(22, 4, "new");

  cout << *phrase << endl;

  delete phrase;
  return 0;
}

Result


Related Tutorials