70,023
社区成员




void test(char *p) //这里不传引用,你的malloc返回值只给到形参p,没有给到实参p,改传引用就是
{
p = (char *)malloc(100);
}
int main(int argc, char* argv[])
{
char *p;
test(p);
strcpy(p, "ok");
return 0;
}
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
void test(char **p)
{
*p = (char *)malloc(100);
}
int main(int argc, char* argv[])
{
char *p;
test(&p);
strcpy(p, "ok");
return 0;
}