What condition is this IF statement checking for? if( !variable )

I saw some code online of people using if statements like this. For example, they will have char variables named "complete" and "wild" and use it like this...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
        if (!complete)
        {
            if (!wild)
            {
			
                break;               // "x" matches "x"
            }
            else if (wild == '*')
            {
                wildString++;
                continue;            // "x*" matches "x" or "xy"
            }
            match = false;
            break;                   // "x" doesn't match "xy"
        }


What does if(!wild) or if(!complete) mean? If WHAT? Its a char variable not a bool so I just didnt understand how it worked. Thanks!
if (!wild) means if ( wild == false ), if (!variable) means if ( variable == false )........
char *wild; You are comparing against NULL (or zero).
But if that your declaration then else if (wild == '*') makes no sense (unspecified behaviour).


EDIT: Sorry I was seeing double quotes ( " " instead of ' ')
if( var ) // Equivalent to if( var!=0 )
Last edited on
adnan2 I mentioned that it was not a bool, and I wasnt aware that a char could be true or false.

ne555 they are just chars not pointers, here are the declarations:
1
2
complete = *completeString;
wild = *wildString;


to me, its like saying if(a)...then do this.... which I don't understand how that really does anything I guess

ne555 i think i see what you first meant,
the only thing I can think of is it saying is this (pseudo code)...

if(the variable wild is null)
{
then do all this
}

in which case the declaration beforehand would have to set wild = NULL or 0.

In c/c++, anything zero is false, anything non-zero is true. true and false are essentially just 1 and 0.
Topic archived. No new replies allowed.