且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

这个&符号在C中是什么意思?

更新时间:2021-12-26 02:12:54

如问题代码中所用,与号&"是按位与"运算.

As used in the question code, the ampersand '&' is a bitwise 'and' operation.

示例(假设 VAR_ON = '21'):

Example (assuming that VAR_ON = '21'):

VAR_ON  21(Decimal)    00010101(Binary)
       & 3(Decimal)  & 00000011(Binary)
       ------------  ------------------
         1(Decimal)    00000001(Binary)

因此,如果 VAR_ON 为21",则表达式 (VAR_ON&3) 的计算结果为1".'if' 条件为假:

Hence if VAR_ON is '21', the expression (VAR_ON&3) will evaluate to '1'. The 'if' condition would be false:

if((VAR_ON&3) > 1)