Where are static variables stored in C and C++?

前端 未结 16 2421
自闭症患者
自闭症患者 2020-11-22 02:00

In what segment (.BSS, .DATA, other) of an executable file are static variables stored so that they don\'t have name collision? For example:


foo.c:                  


        
16条回答
  •  野的像风
    2020-11-22 02:34

    When a program is loaded into memory, it’s organized into different segments. One of the segment is DATA segment. The Data segment is further sub-divided into two parts:

    Initialized data segment: All the global, static and constant data are stored here.
    Uninitialized data segment(BSS): All the uninitialized data are stored in this segment.

    Here is a diagram to explain this concept:

    enter image description here


    here is very good link explaining these concepts:

    http://www.inf.udec.cl/~leo/teoX.pdf

提交回复
热议问题