Doubt regarding Operators

Status
Not open for further replies.
The & operator works with bits and the && operator works with states like boolean.

x = 0x05 & 0xff; /* working with bits */

if(switch_on && fuse_alight){ /* working with boolean */
run_like_f;
}
 

& helps you did bitwise operation, i.e. is actually performing the boolean arithmetic with individual 0's & 1's of two unsigned quantities. The result of it's operation is thus a numeric quantity (treated as unsigned, but C as a language allows you to break that).
&& is a logical operator, which operates on quantities that have logical-meaning of true/false, and the result of it's operation is also either true/false (not a numeric quantity)
 

In an application standpoint.

& is used for performing bitwise operation, such as if you want something like:
result = 0xFF & 0x00; //result = 0

but && operator is used for doing comparison such as:

if( (result > 0x01) && (result < 0x04)) ...
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…