70,020
社区成员




void GetMemory(char *p)
{
p = (char *)malloc(100);
}
void Test(void)
{
char *str = NULL;
GetMemory(str);
strcpy(str, "hello world");
printf(str);
}
void Test(void)
{
char *str = NULL;
GetMemory(&str);
strcpy(str, "hello world");
printf(str);
free(str);
}
void GetMemory(char **p)
{
*p=(char *)malloc(100);
if ( *p == NULL )
printf("申请失败");
}
void Test(void)
{
char *str = NULL;
GetMemory(&str);
strcpy(str, "hello world");
printf(str);
}
void main()
{
Test();
}
void GetMemory(char **p)
{
*p = (char *)malloc(100);
}
void Test(void)
{
char *str = NULL;
GetMemory(str);
strcpy(str, "hello world");
printf(str);
}
/* 一般写成这种类型比较好 */
char *GetMemory ( size_t sz )
{
char *p
*p = (char *)malloc( sz );
return p;
}
void Test(void)
{
char *str = NULL;
str = GetMemory( 100 );
if ( str != NULL ){
strcpy(str, "hello world");
printf(str);
FreeMemory( str );
}
}
void GetMemory(char **p)
{
*p = (char *)malloc(100);
}
void Test(void)
{
char *str = NULL;
GetMemory(&str);
strcpy(str, "hello world");
printf(str);
}