- #include <stdio.h>
- int main()
- {
- struct Student
- {
-
-
- int age;
- char *name;
- };
-
- struct Student stu; //struct Stuetn stu
-
- printf("请输入年龄:\n");
- scanf("%d", &stu.age);
- printf("请输入姓名:\n");
- scanf("%s", stu.name);
- printf("name = %s, age = %d\n",stu.name , stu.age);
- return 0;
- }
复制代码 这段代码的运行结果是正常的:
但如果代码是这样的,运行就出问题了!!请教这时为什么啊?
- #include <stdio.h>
- int main()
- {
- struct Student
- {
-
-
-
- char *name;
- int age;
- };
-
- struct Student stu; //struct Stuetn stu
-
- printf("请输入年龄:\n");
- scanf("%d", &stu.age);
- printf("请输入姓名:\n");
- scanf("%s", stu.name);
- printf("name = %s, age = %d\n",stu.name , stu.age);
- return 0;
- }
复制代码 运行结果是:
|
|