When is memory allotted to static variables in C++

前端 未结 3 771
别跟我提以往
别跟我提以往 2020-12-23 15:42

I am a newbie to C++ and facing a problem.

I read in a book that memory is allotted to a static variable, once the object is created of that class. Now, what if I ma

3条回答
  •  太阳男子
    2020-12-23 15:59

    Static variables are not at all stored in Heap.

    Uninitialized static variables are stored in BSS segment.

    Initialized static variable are stored in Data Segment.

    You can read this article which explains all of it in a great way: http://duartes.org/gustavo/blog/post/anatomy-of-a-program-in-memory

提交回复
热议问题