对于结构体对象在内存中分配地址的顺序及其占内存大小的疑问?
#include <iostream>
using namespace std;
struct NODE
{
NODE* pn;
int value;
};
NODE node1,node2;//全局区(运行结果为图二),区别于下面的栈区
//1、结构体对象不按定义顺序存放,堆?
//2、去掉对ps的定以后,node1、node2所占内存变小?
int main()
{
//NODE node1,node2;//栈区(运行结果为图一)
node1.value = 1;
node2.value = 2;
cout << "&node1 :" << &node1 << ", " <<& node1.pn << endl;
cout << "&node2 :" << &node2 << ", " << &node2.pn << endl;
//cout << "&ps :" << &ps << endl;
return 0;
}
对本程序的运行结果不太明白,如下:
图一:
图二: