69,369
社区成员
发帖
与我相关
我的任务
分享
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;
}