You can see the correct question below:
Void GetMemory (char * p) {p = (char *) malloc (100 );}
Void Test (void)
{
Char * str = NULL;
GetMemory (str );
Strcpy (str, "hello world ");
Printf (str );
}
No response. I don't know where the problem is. I suspect there may be a problem with the GetMemory function. The answer is:The input parameter of the GetMemory (char * p) function is a string pointer. Modifying the parameter inside the function does not actually change the value of the input parameter.I don't know much about this sentence, because the first reaction is in conflict with the concept in my mind. In programming, I always pass in pointers or references to modify and compute external variables in the function, why do we need to talk about this? So I checked the information again. It turned out to be like this. When you want to modify the value pointed to by the pointer, you can pass the pointer. However, when you want to modify the pointer address, such as allocating an address area, you need to input a pointer reference or pointer. These two points reflect the flexibility of the pointer language.