arrray = null?
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]);
}
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++:
Also, use [source] <code goes here> [/source] tags when posting code
ai = null;
is not required, but you should do adelete[] aiNumbers;
somewhere to prevent a memory leak, probably in main, which btw must be declared asint main()//orint main(int argc, char **argv)
Also, use [source] <code goes here> [/source] tags when posting code
Quote:Original post by iMalc
Assuming C++:is not required, but you should do aai = null;
somewhere to prevent a memory leak, probably in main, which btw must be declared asdelete[] aiNumbers;
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
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].
And yes, the second piece of code is flawed. It should not have the [0].
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement