Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if C++ Array is Null

Tags:

c++

arrays

null

how do i do that? well i want to check if the array is empty

like image 357
Luron Avatar asked Oct 04 '10 16:10

Luron


People also ask

How do you check if an array is empty or not in C?

There's no such thing as an "empty array" or an "empty element" in C. The array always holds a fixed pre-determined number of elements and each element always holds some value. The only way to introduce the concept of an "empty" element is to implement it yourself.

How do you check if an element is empty in an array?

To check if an array is empty or not, you can use the . length property. The length property sets or returns the number of elements in an array. By knowing the number of elements in the array, you can tell if it is empty or not.

How do I check if a char array is not empty?

So, if you want to see if a char array is storing an empty string, that means checking whether there are 0 characters, instead of 1 or more characters, before the NUL. Which just means checking the first char to see if it's NUL, aka '\0', aka 0.

How do you check if an element of an array is null C++?

An array in C++ cannot be null; only a pointer can be null. To test whether a pointer is null, you simply test whether it compares equal to NULL or 0 .


2 Answers

An array in C++ cannot be null; only a pointer can be null.

To test whether a pointer is null, you simply test whether it compares equal to NULL or 0.

like image 129
James McNellis Avatar answered Nov 13 '22 07:11

James McNellis


Array in C++ cannot be "empty". When you define an array object, you explicitly specify the exact size of the array. That array contains (and always will contain) that exact number of elements you specified in the definition. No more no less. It will never be "empty".

like image 41
AnT Avatar answered Nov 13 '22 07:11

AnT