Operators new and delete in C++

#include <iostream>
using namespace std;

int main()
{
    int *ptr = new int;
    *ptr = 100;
    cout << "The pointed to value is :" << *ptr << endl;
    delete ptr;

    int *a = new int[3];
    a[0] = 1;
    a[1] = 2;
    a[2] = 3;
    cout << "Values are : " << a[0] << ' ' << a[1] << ' ' << a[2] << endl;
    delete[] a;

    return 0;
}

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *