This question already has an answer here:
x = 1
if(x) {
x equals true
}
but what happens when you put the ! infront:
if(!x) {
x equals ?
}
I see it being used lots in tutorials I read and felt I understood it. But I saw it today and it confused me again.
What does it do? What is it's purpose? why would you use it?
</div>
This means if x==0
or x== false
or not x
as where !x
The exclamation mark merely means not
that is a boolean negation, so
if(!x)
{
(not x) is true, which means x is false
}
For ordinal types of x
that means x == 0
, for pointers x == NULL
.