什么是"!"用C? [英] What is "!!" in C?
问题描述
我也遇到过下面的代码片段:
PT-> AA [!!(TS-GT&;旗帜与放大器; MASK)] = -val;
- 这是什么
!!
在C代表什么? - 不
(!! NULL)== NULL
?
!
是否定。因此, !!
是否定之否定。最重要的是一个事实,即结果将是一个 INT
。
-
!X
如果X == 0
是0!
,即!1
,即0
。 -
!X
如果X!= 0
是!!(!0)
,即!! 1
,即!0
,即1
。
!!
是常用的,如果你想任何非零值转换为1而被肯定,0仍是0。
事实上, !! NULL == NULL
,因为!== NULL 0!
和 0!= =!1
最后!1 == 0
。
因此,在一小段code你提到的数组下标将是要么 0
如果括号中的前pression的值 NULL
和 1
其他。
I have encountered the following snippet:
pt->aa[!!(ts->flags & MASK)] = -val;
- What does
!!
stand for in c ? - Isn't
(!!NULL) == NULL
?
!
is negation. So !!
is negation of negation. What is important is the fact that the result will be an int
.
!!x
ifx == 0
is!!0
, that is!1
, that is0
.!!x
ifx != 0
is!!(!0)
, that is!!1
, that is!0
, that is1
.
!!
is used commonly if you want to convert any non-zero value to 1 while being certain that 0 remains a 0.
And indeed, !!NULL == NULL
, since !!NULL == !!0
and !!0 == !1
and finally !1 == 0
.
Consequently, in the short piece of code you cited the array subscript will be either 0
if the value of the expression in parenthesis is NULL
, and 1
otherwise.
这篇关于什么是"!"用C?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!