Yves Daoust Yves Daoust - 2 months ago 4x
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


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

Yes, this is guaranteed.