Using Exclamation Marks '!' in C
In C, !number will evaluate to 1 if number == 0 and to 0 if number != 0. And in C, 1 is true and 0 is false.
Using an explicit comparison like number == 0 have the same effect but you might find it easier to read.
We can treat !
as not.
So if a number is non-zero (either positive or negative) it returns Zero.
If it is zero, it returns 1.
int i = 13;
printf("i = %d, !i = %d\n", i, !i);
printf("!0 = %d\n", !(0));
It is used for Negation of a number.It is a Unary Operator.
For Example:-
If we are using it with zero :- !0 then it will become 1
with one !1 = 0
It's a negation or "not" operator. In practice !number means "true if number == 0, false otherwise." Google "unary operators" to learn more.