Given this code
int arry[2]; //equal to some values
if (arry[0] & 1) //what does this mean?
{
// do something
}
&
is the bitwise AND operator. Bitwise AND operation performs the logical AND operation for the corresponding bits of each operand. In the case of a & 1
, the left hand operand is the integer a
, and the right hand operand is the integer 1
.
if
keyword is syntax for the if-statement. The simplified grammar of the statement is:
if ( condition ) statement-true
The statement-true
statement is executed only if the condition
expression is true. Here, the type of the condition
expression is an integer type. In this case, the condition is true if the value of the result of the bitwise operation is not zero.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.