struct stu {
const char **str;
int t;
};
int main() {
// test_find_same();
char *arr[] = {"1", "2", "3"};
printf("%s\n", arr[0]);
char **p = arr;
printf("%s\n", *p);
printf("%s\n", *(p + 1));
char **s = malloc(sizeof (char **));
*s = *p;
printf("%s\n", *s);
struct stu *stu;
stu = malloc(sizeof (*stu));
stu->str = malloc(sizeof (char **)); //why malloc
* (stu->str) = *p;
* (stu->str + 1) = *(p + 1);
* (stu->str + 2) = *(p + 2);
printf("%s\n", *(stu->str));
printf("%s\n", *(stu->str + 1));
printf("%s\n", *(stu->str + 2));
// free(stu->str);
free(stu);
return 0;
}
为什么malloc
于 2023-12-28 15:52:32 首次发布