Where are static variables stored (data segment or heap or BSS)?

I got conflicting opinions about the storage of static variables.

Opinion 1: Static variable < retains its value in the heap "

Opinion 2: "Static variable < retains its value in the data segment. "

I am confused by these conflicting answers.

Where are the static variables stored?

I expect answers with links (tutorials, genuine tutorials, etc.).

Static variables have two types:

  • static variables declared inside a function.
  • global (declared external function) static variable.

I would also like to know if there is a difference in storing these two types of variables?

+2
source share
3 answers

" " "", , , bss .

"" , - , . bss . , const-, , ( ).

C , bss. , .

+10

. DATA, DATA , , (, ).

0

.

BSS.

, , . ( , , .. ini var1_global = 10;)

segemnet aka BSS. , main(). .

http://www.geeksforgeeks.org/memory-layout-of-c-program/

0
source

All Articles