I am using test code listed below.
it's giving me a segmentation fault at the delete []ch; line.
#include <iostream.h>
int main()
{
char* ch = new char[3];
ch = "ts";
cout << "ch is: " << ch << endl;
cout << "deleting heap" << endl;
// here is where the problem is.
delete []ch;
cout << "deleted" << endl;
cout << "creating new array" << endl;
ch = new char[3];
cout << "setting value" << endl;
ch = "ab";
cout << "ch is: " << ch << endl;
return 0;
}
Do you know why I'm getting this error?
Any help would be appreciated
Thanks!