RELATIONAL and LOGICAL Operators
For all examples, the initial values are:
tempx=25 (0x19), tempy=5 (0x05), result=0 (0x00)
(Preceding statements not considered)

<

Less Than IF (tempx < 30)
    result = 1;                  
//this will be executed
ELSE
    result = 0;                  
//this will not
<= Less Than or Equal to IF (tempx <= 25)
    result = 1;                  
//this will be executed
ELSE
    result = 0;                  
//this will not
> Greater Than IF (tempx > 20)
    result = 1;                  
//this will be executed
ELSE
    result = 0;                  
//this will not
>= Greater Than or Equal to IF (tempx >= 25)
    result = 1;                  
//this will be executed
ELSE
    result = 0;                  
//this will not
= = is Equal to IF (tempx == 25)
    result = 1;                  
//this will be executed
ELSE
    result = 0;                  
//this will not

//watch out for the common "=" mistake, tempx will be 20 now!
IF (tempx = 20)
    result = 1;                  
//this will be executed
ELSE
    result = 0;                  
//this will not
!= is Not Equal to IF (tempx != 20)
    result = 1;                  
//this will be executed
ELSE
    result = 0;                  
//this will not
&& Logical AND IF ((tempx < 30) && (tempy < 30))
    result = 1;                  
//this will be executed
ELSE
    result = 0;                  
//this will not
| | Logical OR IF ((tempx < 30) || (tempy > 30))
    result = 1;                  
//this will be executed
ELSE
    result = 0;                  
//this will not
! Logical Negation (is Not) IF (!(tempx > 30))
    result = 1;                  
//this will be executed
ELSE
    result = 0;                  
//this will not
SPECIAL Operators
& Address of operand result = & tempx;                 //result: physical ram address
                                  //        of the variable tempx
-> Structure Pointer  
?: Conditional Expression //generally expressed...
//
//result = condition ? expression1 : expression2
//
//if condition is true, result=expression1
//if condition is false, result=expression2


result = tempx > tempy ? tempx : tempy;
    //result:  25
result = tempy > tempx ? tempx : tempy;
    //result:  5

result = tempx > tempy ? tempx * 2 : tempx; //result:  50
result = tempy > tempx ? tempx * 2 : tempx;
//result:  25

//with optional parentheses...
result = (tempx > tempy) ? (tempx * 2) : (tempx);
sizeof Size of operand (Bytes) CHAR tempx;
INT16 tempy;

tempx =
SIZEOF tempx;             //tempx will be 1
tempx =
SIZEOF tempy;             //tempx will be 2

Any questions or comments?
 This page last updated on August 28, 2011