什么是"!"用C? [英] What is "!!" in C?

查看:359
本文介绍了什么是"!"用C?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我也遇到过下面的代码片段:

  PT-> AA [!!(TS-GT&;旗帜与放大器; MASK)] = -val;


  1. 这是什么 !! 在C代表什么?

  2. (!! 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;

  1. What does !! stand for in c ?
  2. 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 if x == 0 is !!0, that is !1, that is 0.
  • !!x if x != 0 is !!(!0), that is !!1, that is !0, that is 1.

!! 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆