MrModest
asked on
Assigning an array using {}'s
I have an array of floats that is declared like:
float x1[3];
I then later want to do something like:
x1 = {1.5,3.2,4.5};
but it seems I can only do that on initialisation. Is there some way to do this such as using an array copy routine?
float x1[3];
I then later want to do something like:
x1 = {1.5,3.2,4.5};
but it seems I can only do that on initialisation. Is there some way to do this such as using an array copy routine?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, I figured I would have to do something like that.
inline void populate_array(float (&x1)[3]) {
float x1_tmp[3] = {1.5,3.2,4.5}; // <---- create a temporary array with the values we want ...
memcpy(x1, x1_tmp, 3 * sizeof(float)); // <---- copy that temporary array into the x1 array
return;
}