Operators

An operator is a special symbol used to perform assignment, arithmetic, comparison or other operation. Here are listed binary operators, that is, operators that are used with two operands, like a+b. See also: unary operators (used with single operand), member access operator . and array element access operator [].

 

Syntax1

operand1 operator operand2

 

For example, a + 1 means "add 1 to the variable a". Here a is operand1, + is operator, 1 is operand2.

 

Syntax2

result = operand1 operator operand2

 

For example, a = b + 1 means "add b and 1, and assign the result to the variable a". Here b is operand1, + is operator, 1 is operand2.

 

Parts

operands - any expressions (variables, constants, functions, expressions with operators). In syntax1, operand1 receives result, therefore it must be lvalue (variable or other expression to which assignment is possible).

result - variable or other lvalue that receives result.

operator - one of symbols listed below.

 

Arithmetic operators
= assign (syntax1)
+ add
- subtract
* multiply
/ divide
% modulus
Bitwise operators
& AND
| OR
^ XOR
~ AND NOT
<< left shift
>> right shift (unsigned)
Comparison operators
=, == equal (syntax2)
!, !=, <> not equal
> more
>= more or equal
< less
<= less or equal
Logical operators
and, && AND
or, || OR
   
   
   
   

 

When operand1 is str variable:

Copy operators (syntax1)
= assign (copy string)
+ append
- append to the beginning
Comparison operators (syntax2)
= equal, case sensitive. Note that "" and null are not equal. Don't use if(s="") to check if s is empty. Instead use if(empty(s)). See also: StrCompare.
! not equal, case sensitive
~ equal, case insensitive

 

Remarks

Syntax1

operand1 receives result of operation. With str can be used only operators =, +, -. As in C, arithmetic and bitwise operators may be followed by =.

 

Syntax2

Operands of type str are interpreted as lpstr (except operand1 with comparison operators =, !, ~). Operands of type lpstr and pointers always are interpreted as numeric (unsigned int). For example if(s1=s2) compares pointers, but not the strings.

 

Comparison and logical operators return 1 or 0. Operator and returns 1 if both operands are not 0. If operand1 is 0, operand2 is not evaluated. Operator or returns 1, if one of operands is not 0. If operand1 is not 0, operand2 is not evaluated.

 

See also: operator priority expression type and precision C run-time library conversions, etc.

 

Examples

i = 5 ;;assign 5 to variable i
i + 2 ;;add 2 to variable i
a = b + 10 ;;calculate sum of b and 5 and assign it to variable a
a + b + 10 ;;calculate sum of b and 5 and add it to variable a
int j = i + 2 ;;declaration and assignment in the same statement
ave = i + j / 2 ;;add j to i, divide by 2, then assign result to variable ave
f = i - (10 * j) + Func(a b) * 10 ;;multiply 10 and j, extract result from i, call function Func and add its return value, multiply by 10, then assign result to variable f
str s = "notepad" ;;declare variable s and assign string "notepad"
s + ".exe" ;;append ".exe"
if(i < 10 and s = "notepad.exe") i + j / 10 ;;if i is less than 10, and s is equal to "notepad.exe", calculate j / 10 and assign result to variable i
i = Func2(j s (i + 5) f) ;;call function Func2 and assign its return value to variable i; pass four arguments, one of them is sum of i and 5 
lef a-10 100 ;;left click; x is a-10, y is 100