Such as: char * a="hello";
This is equivalent to has opened up a storage space to store the string "hello", and then let the pointer points to a string first address 'h',
The problem here:
If the pointer does not point to the string "hello",
It to the other place,
Question: (1) the "hello" string will automatically release the memory, or have to wait for the program close to release the memory?
(2) in the event of the latter situation, had to program such as close to release the memory, this is a memory leak?
CodePudding user response:
1. "hello" string will have to wait until the end of the program will be released, "hello" specific in what position, depending on the compiler, may in the initialization data segment, may also directly in the code segment2. No memory leaks, because "hello" to occupy memory space is not allocated dynamically, when the program is loaded distribution, at the end of the program by the operating system release is very normal, you just like a function call it at beginning when load program once; it also has always been the memory, until the end of the program will be released
CodePudding user response:
Hello, in a constant area