melatonin15
melatonin15

Reputation: 2269

const char **p comparison between pointer and integer if (**p == NULL)

I am defining a function where one of the argument is const char **p. I understand that it means 'declare p as pointer to pointer to const char'. Now I want to check if the const char is NULL character and thus check (**p == NULL) but it gives warning that warning: comparison between pointer and integer. Here is the code example

   bool func(const char **p)
     {   if (**p == NULL)
             return false;}

I am not sure why it's complaining so. Isn't **p supposed to dereference the character value pointer *p points to? Or am I making confusion between NULL and '\0'?

Upvotes: 1

Views: 159

Answers (1)

Clifford
Clifford

Reputation: 93486

NULL is a macro defining a null-pointer constant, not the ASCII character NUL. If you want to test for a character NUL, then:

if( **p == '\0' )

or more simply:

if( **p == 0 )

Upvotes: 4

Related Questions