arrray = null?

Started by
6 comments, last by SOS 18 years, 9 months ago
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]); }

www.computertutorials.org
computertutorials.org-all your computer needs...
Advertisement
What programming language are you using here?
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 :(.
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()//orint main(int argc, char **argv)


Also, use [source] <code goes here> [/source] tags when posting code
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms
This looks like it's either C# or Java...

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()//orint 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
its actually C# sorry I forgot to mention that.

www.computertutorials.org
computertutorials.org-all your computer needs...
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].

This topic is closed to new replies.

Advertisement