谁能告诉我C++到底有没有常量存储区
c吧
全部回复
仅看楼主
level 1
尼吧壩😜
楼主
rt
2022年10月18日 15点10分
1
level 1
尼吧壩😜
楼主
我自己试了,main里面的int和const int是放在一起的,而且是连续的,地址从高到低生长,应该是栈区。
2022年10月18日 15点10分
2
level 1
尼吧壩😜
楼主
而全局/静态的int和static互相之间都是地址连续的,但是const很特别,他的地址看上去也是全局/静态区的,但是跟其他的隔了1k字节,所以这个算是常量存储区吗
2022年10月18日 15点10分
3
level 1
need break
没有
2022年10月18日 16点10分
5
level 1
贴吧用户_QGRURtM
常变量
2022年10月19日 06点10分
6
level 6
Waaaaf
一个变量被const修饰并不意味着它是常量,这仅意味着你无法直接修改该变量的值。
2022年10月19日 08点10分
7
level 1
xianjianmo
傻子才存常量存储区,你一个int,直接内联不香?
2022年10月19日 10点10分
8
level 2
Ewig✨
.rodata,只读数据段,如const char* p = "hello"
2022年10月19日 17点10分
9
level 1
readmoon2
有,但是你要考虑到你的程序是不是会被编译器优化了
2022年10月20日 01点10分
11
level 1
-
c++有只读区也就是常量区,而且要看常量的地址你得用指针存,你用个const那也只是个常变量。
2022年10月21日 04点10分
12
尼吧壩😜
懂了,const只代表权限,不是常量
2022年10月21日 05点10分
level 1
-
常量区不会改变地址都是一致的
2022年10月21日 04点10分
13
level 4
我想当垃圾佬🙈
要不对比一下字符串地址和const修饰的变量的地址
2022年10月21日 06点10分
14
level 1
五次围攻
你可以看看用常量表达式修饰的存在哪里
2022年10月21日 08点10分
15
level 2
Deneo
在函数里面声明static char a[16]和static const char b[16] a在.data节 b在.rdata节,在函数体外则去掉static
2022年10月21日 09点10分
16
level 2
rvnhf
看下elf文件格式和程序装载相关资料
2022年10月21日 16点10分
17
1
2
尾页