|
-
April 18th, 2002, 04:37 AM
#1
Memory leaks ?
Hi everybody,
A simple question. Someone told me that the following code creates inaccessible areas in memory. Tell me more please.
void MyFunc()
{
char* pMyString = "My string";
strcpy(pMyString, "Hello");
}
Many instructions and memory allocations are done by the above code :
- an area which content is "My string" is created, somewhere in the memory ;
- the address of this area is contained in the pMyString pointer.
The strcpy function creates another area and put the string "Hello" in it. Its address is now copy in the pMyString pointer. So, the first area ("My string") is now inaccessible.
My questions are simple :
- is it true ?
- if true, how can I do then ?
Thanks for your help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|