#include <stdio.h>
int main(){
printf("%d,%d\n", 2 & (1<<1) , 2 & (1<<1)>0 );
return 0;
}
the output of this program is 2,0.
2 & (1<<1) is equal to 2 which is more than 0.
so why does 2 & (1<<1) > 0 evaluate to zero??
#include <stdio.h>
int main(){
printf("%d,%d\n", 2 & (1<<1) , 2 & (1<<1)>0 );
return 0;
}
the output of this program is 2,0.
2 & (1<<1) is equal to 2 which is more than 0.
so why does 2 & (1<<1) > 0 evaluate to zero??
Copyright © 2021 Jogjafile Inc.
This expression
is equivalent to
due to the precedence of the operators. That is the relational operator > has a higher precedence than the bitwise AND operator. As
1 << 1is greater than0then the sub-expression( ( 1 << 1 ) > 0 )yields the value1.So
2 & 1yields0because in binary1can be represented (for simplicity) like01and2- like10andIt seems what you mean is the following expression