Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

!! c operator, is a two NOT?

I reading this code, and have this line

 switch (!!up + !!left) { 

what is !! operator ? two logical NOT ?

like image 302
JuanPablo Avatar asked Apr 24 '12 23:04

JuanPablo


People also ask

Which is not a operator of C?

C NOT Logical Operator is used to inverse the result of a boolean value or an expression. ! is the symbol used for NOT Logical Operator in C programming. C NOT Operator takes only one boolean value as operand and returns the result of NOT operation.

Why || is used in C?

Logical OR (||) operator in C Logical OR is denoted by double pipe characters (||), it is used to check the combinations of more than one conditions; it is a binary operator – which requires two operands.

Can you use || in C?

The result of a logical OR ( || operator in C) is true if EITHER of its inputs is true. Similarly logical AND ( && operator in C) is true if BOTH of its inputs are true.


1 Answers

yes, it's two nots.

!!a is 1 if a is non-zero and 0 if a is 0

You can think of !! as clamping, as it were, to {0,1}. I personally find the usage a bad attempt to appear fancy.

like image 96
Armen Tsirunyan Avatar answered Oct 14 '22 14:10

Armen Tsirunyan