S
Shea Martin
Which of the following do I use delete[] instead of just delete.
//1.)
// not sure about this one, as char is of size 1
char *str = new char[10];
//2.)
//not sure about this one, as it is a primitive
int *array = new int[100];
//3.)
// I know I need delete [] for this one
Obj *array = new Obj[2];
//4.)
// what about this one?
//I think I have to manually
//call delete on each element,
//then delete ptrArray?
Obj **ptrArray = new Obj*[2];
ptrArray[0] = new Obj();
ptrArray[1] = new Obj();
//5.)
//similar but a 1 byte primitive
char **strArray = new char*[2];
strArray[0] = new char[10];
strArray[1] = new char[10];
strcpy(strArray[0], "zero");
strcpy(strArray[1], "one");
//I think this is the same as above, but uglier:
char **strArray = (char**)new char[20];
strcpy(strArray[0], "zero");
strcpy(strArray[1], "one");
//6.)
//similar but a multi byte primitive
int **intArray = new int[2];
intArray[0] = new int[10];
intArray[1] = new int[10];
Thanks,
~Shea M.
//1.)
// not sure about this one, as char is of size 1
char *str = new char[10];
//2.)
//not sure about this one, as it is a primitive
int *array = new int[100];
//3.)
// I know I need delete [] for this one
Obj *array = new Obj[2];
//4.)
// what about this one?
//I think I have to manually
//call delete on each element,
//then delete ptrArray?
Obj **ptrArray = new Obj*[2];
ptrArray[0] = new Obj();
ptrArray[1] = new Obj();
//5.)
//similar but a 1 byte primitive
char **strArray = new char*[2];
strArray[0] = new char[10];
strArray[1] = new char[10];
strcpy(strArray[0], "zero");
strcpy(strArray[1], "one");
//I think this is the same as above, but uglier:
char **strArray = (char**)new char[20];
strcpy(strArray[0], "zero");
strcpy(strArray[1], "one");
//6.)
//similar but a multi byte primitive
int **intArray = new int[2];
intArray[0] = new int[10];
intArray[1] = new int[10];
Thanks,
~Shea M.