Checking an array for NULL in C++

Hello All,

I have this question that how to check for an array for NULL?

 
For eg. 
 
#include<iostream.h>
using namespace std;
 
int main()
{
      char arr[10];
      if(arr == NULL)
      {
            cout<<"NULL";
       }
}

Thanks a lott in advance!!!

Include <stdio.h> and that'll work actually. But why would you check if an array's null? It can't be null. If it was a pointer, it might end up as NULL through a mistake.

I might just not understand what you're trying to do, though.

Actually ...wt. I had to check was that if the char pointer has a string initialized or it is not yet initialized.

But I am checking it by doing (strcmp(arr, "")== 0) instead of (arr== NULL), latter which is not correct for the reason you mentioned above!!!!!

Thanks though :):slight_smile:

To check if a string is zero length is easy even without a function call.

if(str[0] == '\0')

But uninitialized doesn't mean zero length, uninitialized means undefined. That means empty only if you're lucky. If you're unlucky it could be full of garbage. Don't check if a string is uninitialized -- don't leave around uninitialized strings, period.