I know that “int *a = new int” is used to allocate memory to contain one single element of type int. The “int *a = new int [5]" is used to allocate a block (an array) of elements of type int. But when I run this code
int *a=new int;
for(int i=0;i<4;i++)
a[i]=i;
for(int i=0;i<4;i++)
cout<<a[i]<<endl;
It runs without any error, and shows the correct output, so when should I use "int *a=new int [5]"? Or are they both same in terms of use? I am using gnu c++ compiler in codeblocks.