有谁可以解释一下下面代码的结果为什么是那样的呢?
老师说跟 堆 栈 有关#include <stdio.h>
#include <stdlib.h>
typedef struct student{
int number; //学号
int age; //年龄
} student;
student * getStudent(){
student stu;
stu.age = 100; //年龄默认初始为岁
stu.number = 100; //学号默认初始为号
return &stu;
}
结果是:student 100 is 100.
student 4241459 is 4325404.
为什么第二个是那样的呢???
void main(){
student * ptr = getStudent();
int age = ptr->age, number = ptr->number;
printf("student %d is %d .\n",number,age);
age = ptr->age, number = ptr->number;
printf("student %d is %d .\n",number, age);
}