Unexplained C++ default int values

前端 未结 6 1610
悲哀的现实
悲哀的现实 2021-01-12 04:55

I\'ve been refactoring some code and I noticed some wonky behavior involving an uninitialized int array:

int arr[ARRAY_SIZE];

I set a break

6条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-12 05:27

    Sometimes in a debug build, the compiler will initialize memory to a known value to make it easier to detect bugs. If your compiler does this, it should be documented somewhere.

    This is entirely at the discretion of the compiler, because the standard doesn't guarantee any initialization whatsoever in this case.

提交回复
热议问题