Click to See Complete Forum and Search --> : checking if an array is null


Mindcraft
03-05-2005, 06:13 PM
im trying to write a function Rm() that deletes the array myArray that was allocated using the "new" operator. If myArray is null, the Rm() function should do NOTHING.

will this work:

Rm
{
if (myArray == null)
// don't know what to put here
else
delete [] myArray;
}


please tell me if this will work. in particular, i am not sure if "myArray == null" is the right way to check if the entire array is null.

buntine
03-05-2005, 09:33 PM
public void rm()
{
if (myArray != null)
// Empty the array.
}

Or you might want to try the length parameter.

public void rm()
{
if (myArray.length > 0)
// Empty the array.
}

This should be in the Java forum.

Regards.

ray326
03-05-2005, 11:51 PM
Looks more like Javascript to me.

buntine
03-06-2005, 12:26 AM
Well, it would not work in either environment.