Arduino - Boolean Operators



Assume variable A holds 10 and variable B holds 20 then −

Operator name Operator simple Description Example
and && Called Logical AND operator. If both the operands are non-zero then then condition becomes true. (A && B) is true
or || Called Logical OR Operator. If any of the two operands is non-zero then then condition becomes true. (A || B) is true
not ! Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false. !(A && B) is false

Example

void loop () {
   int a = 9,b = 4
   bool c = false;
   if((a > b)&& (b < a))
      c = true;
   else
      c = false;

   if((a == b)|| (b < a))
      c = true;
   else
      c = false;

   if( !(a == b)&& (b < a))
      c = true;
   else
      c = false;
}

Result

c = true
c = true
c = true
arduino_operators.htm
Advertisements
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy