Link to home
Start Free TrialLog in
Avatar of MrModest
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?
ASKER CERTIFIED SOLUTION
Avatar of Infinity08
Infinity08
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oh, and a good idea is to inline that function :

    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;
    }
Avatar of MrModest
MrModest

ASKER

Thanks, I figured I would have to do something like that.