双指针的问题
void GetMemory( char **p, int num ){
*p = (char *) malloc( num );
}
void Test( void )
{
char *str = NULL;
GetMemory( &str, 100 );
strcpy( str, "hello" );
printf( str );
}
请问为啥是&str,这是代表*p=&str吗?如果换成str行不行?
void get_memory(char *p, int n) { p = (char *)malloc(n); } int main(void) { char *str; get_memory(str, 10); strcpy(str, "hello"); printf("%s\n", str); return 0; }