I would like to know if it is possible to initialize an array by assigning values. Is the only way iterating with a for
?
Something that is very easy in Javascript is to declare a variable assigning values, and also has the advantage that it is not necessary to indicate the length of the array, in comparison with C ++ .
var array=[1,2,3,4,5]
If I do I put the 5
in the brackets in C ++ , I have no problem, compile and everything:
int array_enteros[5]={1,2,3,4,5};
But when I do the following:
int 5;
int array_enteros[digitos]={1,2,3,4,5};
The CodeBlocks throws me an error:
Warning: extended initializer lists only available with -std = c ++ 11 or -std = gnu ++ 11 [enabled by default]
error: assigning to an array from an initializer list
error: variable-sized object 'array_enteros' may not be initialized
What I would like to do is declare an array but indicating the length by a variable, or if possible, it would be much better not to use the variable, and change the length automatically depending on the number of values that I give assign.