【发布时间】:2020-07-14 13:58:03
【问题描述】:
#include<stdio.h>
struct student_college_detail
{
int college_id;
char college_name[50];
}stud;
int main()
{
struct student_college_detail stud= {71145,"Anna University"};
printf(" College Id is: %d \n",stud.college_id);
printf(" College Name is: %s \n",stud.college_name);
return 0;
}
例如在上面的程序中,对象 "stud" 存储在内存中的什么位置?是堆还是栈?
【问题讨论】:
-
定义出现在函数内部还是外部?
-
@Keerthana 您没有显示此声明发生的位置..
-
我们只能说它不是堆分配的变量,只是动态分配的内存来自“堆”。否则,它取决于您定义结构对象的 where。请edit您的问题包括minimal reproducible example。
-
无处可去。在这里你只是定义它而不是实例化它。
-
@Ra'Jiska 如果在
struct之前有一个typedef然后stud将是类型,那么@Ra'Jiska 将是正确的,但这里stud是struct student_college_detail的一个实例。
标签: c memory memory-management structure heap-memory