c++ - set array indexes many at once? compound literals? -


index = {27,27,27,27,27}; //as many rootsize 

compiler gives me error when try in function. index globally initialized in same file with:

int index[5]; 

error: expected expression index = {27,27,27,27,27}; //as many rootsize

is not legal? how set array values @ once? need loop?

you cannot directly assign array. can, however, memcpy() compound literal:

#include <string.h>  memcpy(index, (int [5]){ 27, 27, 27, 27, 27 }, sizeof index); 

note compound literals c feature, not c++.


Comments