When do C++ POD types get zero-initialized?

前端 未结 5 1862
隐瞒了意图╮
隐瞒了意图╮ 2020-12-10 03:23

Coming from a C background, I\'ve always assumed the POD types (eg ints) were never automatically zero-initialized in C++, but it seems this was plain wrong!

My unde

5条回答
  •  温柔的废话
    2020-12-10 03:50

    For me, POD types are initialized depending on the part of the memory they are placed. Your static int a is allocated on the data segment, so it has a default value on startup. However, I think f is not inizialized in your example...

提交回复
热议问题