结构内存分配 [英] Structure memory allocation
本文介绍了结构内存分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
struct node{
int data;
struct node * next;
};
当我们尚未为结构"struct node"分配内存时,编译器如何为"next"成员分配内存
How does the compiler allocate memory for "next" member in when we have not yet allocated memory for the structure "struct node"
推荐答案
next
成员是一个指针-一个将包含地址node
而不是node
本身的变量.所有数据类型的指针通常都具有相同的大小,因此对于编译器来说,知道它是一个能够计算其大小的指针就足够了.
next
member is a pointer - a variable that will contain an address of node
, not node
itself. All data type pointers are usually of the same size so it's enough for the compiler to know that it's a pointer to be able to compute its size.
这篇关于结构内存分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文