Sign in to follow this  

Array Assignment

This topic is 4869 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This is probably a really simple question...but it's botherin me, and I can't find anything on [google]. In c++ it's possible to initialize an array like so...
float array[] = {1.1, 2.2, 3.3, 4.4};

But is there any way to make a similar assignment after you declare the array without individually assigning each element? Here's what I want to do...but it's obviously a compilation error.
// Want to Do...
float array[4];

array = {0.0, 1.1, 2.2, 3.3};

// Don't want to have to do... 
float array[4];

array[0] = 0.0;
array[1] = 1.1;
array[2] = 2.2;
array[3] = 3.3;

Also, one other question about floats...is there a reason some implementations put an "f" after the number like... float x = 2.33f; Thanks!

Share this post


Link to post
Share on other sites
Hrm...it makes sense logically for that to be the case, but what does it ultimately do? Is it just good practice or will it get rid of compilation errors because of the compiler thinking you're assigning a double to a float variable?

Thanks for responding, I just don't see the purpose :)

Share this post


Link to post
Share on other sites
Quote:
Original post by Malikive
Is it just good practice or will it get rid of compilation errors because of the compiler thinking you're assigning a double to a float variable?

Yep, MSVC gives warnings about that sometimes.

About the original problem - Nope, theres no way to do it like that. You could create a tempoary array and memcpy it, but that'll be slow (unless the compiler has some pretty good intrinsics), and pointless.

Share this post


Link to post
Share on other sites
Awesome, thanks for the info. I wasn't sure if you could or not, but that makes sense. I did figure out what I was trying to do anyways by just using initialization.

Thanks for your responses!

Share this post


Link to post
Share on other sites

This topic is 4869 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this