2024年5月28日发(作者:)
C++程序内存布局探讨(一)
刘昕 重庆大学软件学院
摘要:
本文探讨了C++程序内存布局的基础知识,对堆、栈、全局数据区和代码区的概念进
行了简单介绍,并介绍了内存对齐和进程地址空间(虚拟内存)方面的知识。
今天一大早起来,收到外校的同学传给我的一道C++面试题,该公司做Windows平
台下的C++开发。面试题有一道考C++程序内存布局,很具有代表性。
已知有这样一段代码:
#include
#include
using std::string;
using std::cout;
using std::endl;
int global_a = 5; //全局对象
static global_b = 6; //全局静态对象
int main()
{
int a = 5; //声明一个变量5
char b = 'a';
int c = 8;
static int d = 7;
cout<<&a< cout<<&c< cout<<&d< cout<<&global_a< cout<<&global_b< return 0;


发布评论