Expressions  Comparison operators

Chapter 1: Overview

Arithmetic operators

Arithmetic operators are grouped left to right. When a statement contains more than one operator, the operations are performed in their order of precedence. See “Operator order of precedence” for information about the precedence of the arithmetic operators.

Use parenthesis ( ) to perform operations in non-precedence order. For example, for d = a + b * c, the variable “d” contains the result of “b” multiplied by “c”, then added to “a”, while for d = (a + b) * c, the variable “d” contains the result of a plus “b” multiplied by “c”. In the examples shown in Table 1-3, “a”, “b”, and “c” are integer data.

NoteAlways put a space character between the addition or subtraction operators and the data, so that the data parser does not mistake them for sign characters rather than arithmetic operators. For example: c = 20 - 10; not: c = 20-10.

Table 1-3: Expressions, arithmetic operations

Operator

Description

Example

=

Assignment.

Complex assignment/initialization.

a = b;

Struct sample = {1,2,3,54,85};

+

Addition

c = a + b;

+=

Add and assign

a += b;

-

subtraction

c = a - b;

-=

Subtract and assign

a -= b;

*

Multiplication

c = a * b;

*=

Multiply and assign

a *= b;

/

Division

c = a / b;

/=

Divide and assign

a /= b;

%

Modulus

c = a % b;

%=

Modulus and assign

a % = b;

++

Increment: Pre-increment

Post-increment

++a/b; (same as a = a + 1;a/b;)

a++/b; (same as a/b; a = a + 1;)

--

Decrement: Pre-decrement

Post-decrement

--a/b; (same as a = a - 1; a/b;)

a--/b; (same as a/b; a = a - 1;)





Copyright © 2005. Sybase Inc. All rights reserved. Comparison operators

View this book as PDF