Page 44 - Open Soource Technologies 304.indd
P. 44
Web Technologies-I
Notes
The plus sign (+) is an operator. The numbers to either side of it are said to be its arguments,
or operands. An argument or operand is something that an operator takes action on. Different
operators have different types and numbers of operands. (You will also find that some operands
are overloaded. This means that they will do different things in different contexts.)
Two or more expressions connected by operators are called an expression. That’s right. You use
operators to make complex expressions. The more sub-expressions and operators, the longer
and more complex the expression, but as long as it is something that equates to a value, it is still
an expression.
When expressions and operators are assembled in such a way as to produce a piece of code
that actually does something, you have a statement. Statements end in semicolons and are the
programming equivalent of the complete sentence.
For instance, $a + $b is an expression. It equates to something, the sum of the values of $a and
$b, but it does not do anything. $c = $a + $b; is, on the other hand, a statement, because it does
something. It assigns the sum of the values of $a and $b to $c.
Since there is not really much to understand about expressions except for the assembly of them
into compound expressions and statements using operators, we are going to look at the operators
used to turn expressions into more complex expressions and statements.
Table 2.1: Operator Precedence
P A Operator Operation
19 N new Create new object
18 R [ Array subscript
17 R ! Logical NOT
R ~ Bitwise NOT
R ++ Increment
R -- Decrement
R (int), (double), (string), (array), (object) Cast
R @ Inhibit errors
16 L * Multiplication
L / Division
L % Modulus
15 L + Addition
L – Subtraction
L . String concatenation
14 L << Bitwise shift left
L >> Bitwise shift right
13 N <,<= Less than, less than or equal
N >,>= Greater than, greater than or equal
12 N == Value equality
N !=, <> Inequality
N === Type and value equality
N !== Type and value inequality
11 L & Bitwise AND
Contd...
38 LOVELY PROFESSIONAL UNIVERSITY