Yves Daoust Yves Daoust - 3 months ago 22
C++ Question

Initializing an array of zeroes

It is well known that missing initializers for an array of scalars are defaulted to zero.

int A[5]; // Entries remain uninitialized
int B[5]= { 0 }; // All entries set to zero


But is this (below) guaranteed ?

int C[5]= { }; // All entries set to zero

Answer

The empty braced initialisation performs aggregation-initialization of the array: this leads to zero-initialization of the int elements.

Yes, this is guaranteed.