As exposed above, an array of ints can't have "empty" elements. However, you can always determine a convention if you want to. For instance, if you're only interested in positive integers, you could use -1 to signal an "empty" slot (maybe define a const int empty = -1). Be sure to document this kind of thing well, though, because it's quite non obvious.
In C++, NULL is 0. Literally. This means it can even be assigned to an int or anywhere a 0 is acceptable. Conventionally, it's only used with pointers.
The deceleration of NULL is the following( if you're interested ):
#define NULL( ( void * )0 ) // This is it I believe.
In C++, NULL is 0. Literally. This means it can even be assigned to an int or anywhere a 0 is acceptable.
While this is true, it could be misleading to others thinking that the variable they're working with is a pointer. So, only using NULL with hanging pointers is the smart thing to do.
it could be misleading to others thinking that the variable they're working with is a pointer.
Agreed.
So, only using NULL with hanging pointers is the smart thing to do.
Often, if you have a function that allocates some memory and returns a pointer to it, you'll want it to return NULL if it fails to allocate (or something else goes wrong).
In what situation do you want the array to be empty? Most of the time if you want half of the array to be empty you just wont use that many allocated addresses example, instead of using [10] you would use [5].