Hi all,
I want to create a pointer to a C-String like so:
Code:
char *pCString = "This is a string";
and then delete the memory reserved for the C-String:
From what I understand, this just deletes the memory pointed to by pCString. So couldn't I still use this pointer? I mean, reallocate memory for another string like so:
Code:
pCString = "This is another string";
Here is an example of the full source code:
Code:
#include <iostream>
int main()
{
char *pC_String = "This is a string";
std::cout << pC_String << std::endl;
delete pC_String;
pC_String = "This is another string";
std::cout << pC_String << std::endl;
system("PAUSE");
return 0;
}
Now, i'm pretty darn sure that when I try to allocate memory for the new C-String, my program crashes. What am I missing? I want to be able to point to another value without keeping the other value in memory.
If I was unclear, please say so and I will try to reiterate my question.
Thanks!