Check if C++ Array is Null

Actually, when you have an array a[SIZE], you can always check:

if( NULL == a )

But it’s not necessary, unless you created a dynamic array (using operator new).

See the other answers, I won’t delete it just because it’s accepted now. If other answer is accepted, I’ll delete this “answer”.

EDIT (almost 4 years later 🙂 )

As I get many down-votes for this, I’d like to clarify: I know this is useless and a will never be NULL, but it technically answers the question about the NULL part.

Yes, it does NOT mean, the array is empty, NOT at all. As @JamesMcNellis notes below, arrays cannot be NULL, only pointers.

It could only be useful for dynamically allocated arrays with initialized pointer before the allocation.

Anyway, I’ll wait for accepting other answer and will delete mine.

Leave a Comment