70,023
社区成员




#include <stdio.h>
#include <string.h>
void test(char *point);
int main(void )
{
char *pt1 = "haoren";
char *pt2;
pt2 = (char *)malloc(sizeof(pt2));
pt2 = pt1;
printf("pt2 is %s\n",pt2);
return 0;
}
#include <stdio.h>
#include <string.h>
void test(char *point);
int main(void )
{
char *pt2;
pt2 = (char *)malloc(sizeof(pt2));
test(pt2);
printf("pt2 is %s\n",pt2);
return 0;
}
void test(char *point)
{
char *q = {"haoren"};
strcpy(point, q);
// point = q;
}
这可以更改所指向的值,但是下面的代码应该是乱数据。
#include <stdio.h>
#include <string.h>
void test(char *point);
int main(void )
{
char *pt2;
pt2 = (char *)malloc(sizeof(pt2));
test(pt2);
printf("pt2 is %s\n",pt2);
return 0;
}
void test(char *point)
{
char *q = {"haoren"};
// strcpy(point, q);
point = q;
}