How object created by new destory?

I am still confused about how object create by new being destroyed
consider the following example:

class C{...};
char* void test(){
char *a = new char[100];
char *b = new char[100];
char *c = new C;
return a;
}

void test2(char* a){

delete []a;
}

main{
char* a= test();
test2(a);
}


what's the lifetime of a,b,c?
Is there any difference between life time after newing a build-in type and a class object?


Thanks in advance
They would all die when the function is done.
ResidentBiscuit wrote:
They would all die when the function is done.

Not exactly, the pointers "die" after the function exits creating 2 memory leaks.
Topic archived. No new replies allowed.