The usage of delete

Hi,

I am wondering in the following context, should I use delete or delete[]? Thanks.

struct node{

int val;
node * lnode;
node * rnode;
};

int main(){
node * nd = new node;
delete nd; or delete[] nd?
}

I have this question because nd has two pointers. Thus I am not sure whether I should use delete or delete[]. Thanks.

Use delete.
closed account (Dy7SLyTq)
you use delete when you use new and you use delete[] when you use new[]
I have this question because nd has two pointers.

What does that have to do with it?

Note that by deleting an instance of node, you are not automatically deleting the objects that lnode and rnode point to. If you want those to be deleted too, then you'll need to write a destructor that does it.
Topic archived. No new replies allowed.