Datasheet
Chapter 1: A Quick Introduction to Programming
18
      Operators and Operator Precedence 
 An operator acts on one or more operands when comparing, assigning, concatenating, calculating, and 
performing logical operations. Say you want to calculate the difference between two variables 
X  and Y 
and save the result in variable 
Z . These variables are the operands and to find the difference you use the 
subtraction operator like this:
 Z = X - Y
   Here you use the assignment operator ( = ) to assign the difference between X  and Y , which was found by 
using the subtraction operator ( 
- ). 
 Operators are one of the single-most important parts of any programming language. Without them, you 
cannot assign values to variables or perform calculations or comparisons. In fact, you can’t do much at all. 
 There are different types of operators and they each serve a specific purpose, as shown in the 
following table. 
        Operator    Purpose  
 assignment  ( = )       The most obvious and is simply used for assigning a value to a variable or 
property. 
    arithmetic       These are all used to calculate a numeric value, and are normally used in 
conjunction with the assignment operator and/or one of the comparison 
operators. 
    concatenation       These are used to concatenate (“join together”) two or more different 
expressions. 
 comparison   These  are  used  for  comparing  variables  and  expressions  against  other 
 variables, constants, or expressions.  
    logical       These are used for performing logical operations on expressions; all logical 
operators can also be used as bitwise operators.  
    bitwise       These are used for comparing binary values bit by bit; all bitwise operators 
can also be used as logical operators.  
Figure 1-7
 Figure 1-7  shows the final summary message generated by the code. Notice how well the information is 
integrated. 
c01.indd 18c01.indd 18 8/27/07 7:45:23 PM8/27/07 7:45:23 PM










