Array initialization with empty list "{}" in C ++

1

From what I've seen, it's possible to initialize a vector with the empty list, in C ++, but not in C, so that all vector elements are 0:

int meuVetor[10] = {}; // Todos os elementos 0, em C++

What I learned in this answer from SOEn.

Is it possible, however, to initialize an array in this way?

int minhaMatriz[10][10] = {};

Would all of your elements be 0?

In what I tested, it only gave segmentation failure, but I do not know if it was related.

    
asked by anonymous 24.03.2016 / 22:40

1 answer

2

You can do this. Some compilers may complain and require a slightly different syntax:

int minhaMatriz[10][10] = {{0}};
    
24.03.2016 / 22:48