对于程序的不同运行,全局变量的地址是否相同? [英] Is address of global variables the same for different runs of the program?

查看:52
本文介绍了对于程序的不同运行,全局变量的地址是否相同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下代码段

int i=10;
int main()
{
    cout<<&i;
}

一旦为该程序生成了一个exe,对于该程序的不同运行,输出将是相同的吗?假设操作系统支持虚拟内存

Once an exe is generated for the program, will the output be the same for different runs of the program? Assume that the OS supports virtual memory

查询特定于存储在数据段中的全局变量.由于这是第一个全局变量,因此地址应该相同还是不同?

The ques is specific to global variables which are stored in data segment. Since this is the first global variable, should the address come out to be same or different?

推荐答案

如果 ASLR,您将始终获得相同的地址已禁用.如果启用了ASLR,您将获得无法预测的地址.

You always get the same addresses if ASLR is disabled. You get unpredictable addresses if ASLR is enabled.

这篇关于对于程序的不同运行,全局变量的地址是否相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆