Hi all,
I want to create a pointer to a C-String like so:
and then delete the memory reserved for the C-String:Code:char *pCString = "This is a 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:delete pCString;
Here is an example of the full source code:Code:pCString = "This is another string";
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.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; }
If I was unclear, please say so and I will try to reiterate my question.
Thanks!



LinkBack URL
About LinkBacks


