Char * get_str (void)
{
Char STR [] = {"ABCD "};
Return STR;
}
Char STR [] = {"ABCD"}; defines an array of local characters. Although it is an array, it is a local variable, the returned address must be the address of the space that has been released.
This function returns the internal STR address of a local character array, and the array is destroyed after the function is called. Therefore, the pointer you return also points to a piece of memory that is destroyed, this statement is incorrect.
Char * get_str (void)
{
Char * STR = {"ABCD "};
Return STR;
}
Char * STR = {"ABCD"}; defines a String constant and assigns its address to Str.
The return value of this function is the address of the String constant, and the nominal value of a string like this is global. The memory has been allocated during compilation, and onlyProgramIt will be destroyed only when exiting, so it is okay to return its address, but you 'd better return a constant pointer because you cannot change the value of a String constant.