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.