Jump to content
  • Advertisement
Sign in to follow this  
Malikive

Array Assignment

This topic is 5152 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!