how do i do that? well i want to check if the array is empty
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.
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.
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.
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 .
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
.
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".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With