#include<stdio.h> #include<stdlib.h> #include<string.h> typedef struct stu{ char *name,gender; int score; }STU; void f(char *p) { /*p=(char*)malloc(10);*/ strcpy(p,"qian"); } main() { STU a={NULL,'m',290}; a.name=(char *)malloc(10); strcpy(a.name,"zhao"); f(a.name); printf("%s\n",a.name); }
为什么加上注释掉的那句后,输出的结果就变了?malloc函数不就是分配了地址和空间吗?
angie
慕粉1239569501
相关分类