Question: I was learning how to use the delete operator for dynamic arrays and i ran into some really strange problem. I tried two approach to write the same code - one worked but the other dint work. So, here is the code i tried

Method 1:- 

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

int main()
{

  int *p = new int(2);

   for(int i =0; i<2;i++)
   {
       cin>>p[i];

   }

   for(int i=0; i<2;i++)
   {
       cout<<p[i];

   }

      delete[] p;

     system("pause");
}

```

//Error message - Heap Corruption detected. Can someone please explain me the reason of the error?

Method 2:- Using TypeDef 

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

typedef int arr[2];

int main()
{

  int *p = new arr;

   for(int i =0; i<2;i++)
   {
       cin>>p[i];

   }

   for(int i=0; i<2;i++)
   {
       cout<<p[i];

   }

      delete[] p;

     system("pause");
}

```

//The above method works perfectly with no error. I am totally confused!!

Answer: 
You're calling the constructor of *one* int with the value of `2` not **allocating** *two* ints.

Use square brackets instead.

```
int *p = new int[ 2 ];

```
in your first example you have:

```
int *p = new int(2);

```

which is initializing 1 pointer to the value of 2 rather than in your second example when you have a

```
new int[2];

```

where you're actually making 2 pointers.