Can't delete array

1
2
int myarray[10] = {1,2,3,4,5,6,7,8,9,0};
delete [] myarray;


Returns:

expected unqualified-id before 'delete'


Does anyone know why?
Why are you trying to delete something that you did not "new"?
You should not be deleting an array that you did not create using new.

And if you do have something to delete you need to put the statement into a function like this:
1
2
3
4
5
6
int* myarray = new int[10]; 

int main()
{
    delete[] myarray;
}
Last edited on
Thanks guys.
Topic archived. No new replies allowed.