Do static members of a class occupy memory if no object of that class is created?

前端 未结 3 552
旧时难觅i
旧时难觅i 2020-12-01 06:54

Say I have a class and I have a static member in it, but I don\'t create any objects of that type. Will the memory be occupied for the static variable? If it would be occupi

3条回答
  •  攒了一身酷
    2020-12-01 07:13

    Static variables are stored in a special memory area called BSS, while instances of a class are stored in a heap or on a stack. So, static members are stored separately.

提交回复
热议问题