What do you use?

What do you use around the variable?

1
2
3
4
int kill;
int num[10]={1,2,3,4,5,6,7,8,9,10};
cin>>kill;
delete num[kill];//what do you put around the int kill? 


Thanks.
Last edited on
You wouldn't use delete on that variable at all.

You only delete what you allocate with new.
So:
1
2
3
4
5
6
7
8
9
10
11
12
int var1 = 5;
//delete var1; // Bad
int* var2 = new int(5);
delete var2; // Good

int myArray1[] = {1,2,3,4};
//delete myArray1; // Bad
//delete myArray1[2]; // Bad
//delete[] myArray1; // Bad
int* myArray2 = new int[4];
//delete myArray2; // Bad
delete[] myArray2; // Good 
Thanks, what is a new?
Last edited on
I don't want to delete the array, I only want to delete one element of the array.
Last edited on
New allocates on the heap instead of on the stack. You can't simply delete an element from a static array. You could give it an "deleted" value though like -1 or something. Then if you try and use that value display an error message or something.
Problem solved!
Topic archived. No new replies allowed.