How to tell if array contains anything?

Here is a snippet of my code:

  if ( a != null )    

I don't know how to fix this issue:

RFID_reader:246:13: error: 'null' was not declared in this scope
   if ( a != null )                       // Make sure there is something in the array first
             ^~~~
exit status 1
'null' was not declared in this scope

I know null is not defined but I want to find a way to detect if an array contains anything.

NULL should be all caps..
but this will only check if the pointer is valid..

~q

ok lemme check thx

Yayyyy it worked :smiley:

What sort of array? Post the actual code.

If you declare an array, then you can initialize it to contain certain values. There should be no confusion about whether an array "contains anything", since you are in control.

A standard C / C++ array will always contain SOMETHING ... even if it's random / garbage data. The storage space has been allocated, it can't contain NOTHING!

Without seeing the context of a snippet, it is hard to see why you think you have a solution.

Which you may well have, but as pointed out, an array will,always have something in it.

If you meant an array of characters, a C string, then it is a meaningful question.

Or maybe you want to see if any elements of an array have non-zero values - that you have to do by looking…

Or maybe you are passing an array to a function and want to be sure it really exists (pointer is valid, non-null).

So provide some context or say what you are really trying to determine.

a7