Files
Sec-Interview/_book/Chapter23/23-3.md
T
2025-11-08 21:00:06 +08:00

9 lines
664 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
### .data 段存放哪些数据
`.data` 段,即数据段,主要存放**已经初始化的全局变量和静态变量**
当编译器编译程序时,如果发现一个全局变量或静态变量被赋予了一个非零的初始值(比如 `int global_var = 10;`),那么这个变量的值就会被存储在`.data`段中。这个段在可执行文件(比如`.exe` 或可执行的 ELF 文件)中是实际存在的,并占用文件空间。当程序加载到内存时,操作系统的加载器会把这部分数据原封不动地加载到内存中
- **例子**
- `int initialized_global = 100;`
- `static char static_string[] = "Hello World";`