View Full Version : c++ help (again)
wo1olf
02-02-2007, 06:57 PM
How can it test if an array is empty at a given position (index) ?
like in this way
if(array[i] != ...)
{
}
Yeldarb
02-02-2007, 09:42 PM
if(array[i] != null) {
}
MTsoul
02-02-2007, 11:28 PM
Are you sure about that Yeldarb? Are all array entries initialized to null before assginment?
kopo.fett
02-03-2007, 09:14 PM
for (int i = 0; i < arrayName.Length; i++)
{
if (arrayName[i] != null) {
// array element is not empty
}
else {
// array element is empty
}
}
Yeldarb
02-03-2007, 11:37 PM
Are you sure about that Yeldarb? Are all array entries initialized to null before assginment?
No, I don't think they are (I seem to remember having uninitialized variable with arbitrary left-over bits in them but it's been a while).
But if they do have arbitrary bits then they are assigned, aren't they? There's no real way to tell whether you assigned them or they're left overs.
Best bet is to manually go through and initialize them to null I'd say.
TheColonial
04-08-2007, 05:05 AM
Dont forget that 'NULL' is actually defined as 0 on most platforms. Does 0 always mean empty? :) I don't think so! An array of integers can easily contain zero, that doesn't mean it's empty.
It's up to you to keep track of what's used and what's not.
Cheers
OJ
vBulletin® v3.8.4, Copyright ©2000-2010, Jelsoft Enterprises Ltd.