mardi 2 février 2016

Ways to initilize array container in C++

(I apologize if I do not use terminology correctly or if I am asking an obvious question. I only recently started learning C++)

I've seen that the most examples online use the following way to initialize array container:

std::array<int,3> myarray = { 2, 16, 77 };

But I tried doing the following:

std::array<int,3> myarray;

myarray[0] = 2;
myarray[1] = 16;
myarray[2] = 77;

Seems to be working too. Is first method preferred over the second or is the second one simply incorrect?

Aucun commentaire:

Enregistrer un commentaire