#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct Student{
char* name;
char* id;
int age;
};
int main(){
struct Student student;
student.name=(char*)malloc(10);
student.id=(char*)malloc(10);
student.name=“jack”;
student.age=18;
student.id=“0001”;
printf("%s\n",student.name);
printf("%s\n",student.id);
system(“pause”);
return 0;
}
()malloc();是用来进行动态赋值的,用来分配内存空间的;
为什么要分配空间呢?
因为上述代码中利用了指针,而指针是没有内存的;