双指针的问题
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行不行?
2016-07-19 14:11
2016-07-19 14:28
2016-07-19 14:38
2016-07-19 15:06
2016-07-19 16:29
2016-07-19 22:47
2016-07-21 10:33
2016-07-21 11:05
2016-07-21 15:44
程序代码:
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;
}

2016-07-23 12:12