Jump to content
  • Advertisement
Sign in to follow this  
sevak

arrray = null?

This topic is 4864 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

I was just wondering do I need the ai = null in this method? static void ChangeArray(int[] ai) { ai[0] = 55; ai = null; } Also the book I am reading has this main method. However, it seems pretty weird that the author is passing an index of an array instead of the whole array. Is this a error or am I wrong? static void Main() { int[] aiNumbers = new int[5]; ChangeArray(aiNumbers[0]); }

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
What language is this in? In any case I think there is no reason for the null line. Also the main doesnt seem like it will compile... I think your book is not very good :(.

Share this post


Link to post
Share on other sites
Assuming C++:
ai = null;
is not required, but you should do a
delete[] aiNumbers;
somewhere to prevent a memory leak, probably in main, which btw must be declared as
int main()
//or
int main(int argc, char **argv)


Also, use [source] <code goes here> [/source] tags when posting code

Share this post


Link to post
Share on other sites
Quote:
Original post by iMalc
Assuming C++:
ai = null;
is not required, but you should do a
delete[] aiNumbers;
somewhere to prevent a memory leak, probably in main, which btw must be declared as
int main()
//or
int main(int argc, char **argv)


Also, use [source] <code goes here> [/source] tags when posting code


Actually I think it's java, so this isn't necessary
sevak, I think you are right--it should be passing the whole array
Otherwise it makes no sense and won't even compile

Also, setting ai equal to null won't have any effect here, so you don't need it

Share this post


Link to post
Share on other sites
Setting array to null will do absolutely nothing in the first function, so it's completely pointless.

And yes, the second piece of code is flawed. It should not have the [0].

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!