Is there a way to set all values of an array after initialization with a single line of code?
For example, I can do this: int array[4] = { 1, 2, 3, 4 }
.
However, later on I cannot simply write: array = {4, 3, 2, 1};
to set the array to something else.
Would definitely guess cause it does not know that {4, 3, 2, 1}
is an array of ints, but then how do I tell it that it is?
I have found workarounds like:
int tempArray[4] = {4, 3, 2, 1};
array = tempArray[4];
or
array[0] = 4;
array[1] = 3;
array[2] = 2;
array[3] = 1;
However I would definitely prefer not to have to use those workarounds, but instead have something like array = int[4] {4, 3, 2, 1};
.