Unary operators




Example: -10. Here - is operator, 10 is operand.



! The logical-negation (logical-NOT) operator produces the value 0 if its operand is true (nonzero) and the value 1 if its operand is false (0). The result has int type.
~ The bitwise-complement (bitwise-NOT) operator produces the bitwise complement of its operand. The result has the type of the operand.
- The arithmetic-negation operator produces the negative of its operand. The result has the type of the operand.
* The indirection operator accesses a value indirectly, through a pointer. The operand must be a pointer value. The result is the value at the address to which operand points. The type of the result is the type that the operand addresses.

The address-of operator gives the address of its operand. The operand can be either a variable or a function name. The result is a pointer to (address of) the operand. If operand is non-initialized reference-variable, result is 0.

+ The type cast operator. Can be used in some assignment operations (=, ret, function arguments) to avoid "type mismatch" error. With interface pointers, it queries interface at run time. With lpstr and pointers, it simply passes raw value. It does not convert number to string; instead assign the number to a str variable and use it. It does not convert string to number; instead use function val.
@ QM 2.3.0. Converts string to Unicode UTF-16. The operand must be a string (lpstr or str). The result is Unicode UTF-16 string. Use when calling dll and COM functions that accept UTF-16 strings. Parameter type usually is @* (word pointer; in C++ would be LPWSTR, OLECHAR* or similar), but also can be BSTR or int (for example with SendMessageW). Example.



Unary operators must be placed immediately before operand. With operators !, ~ and -, operand can be any expression. With operator *, operand can be any expression that has pointer type.


Unary operators are applied before binary operators, but after operators . (member access) and [] (array element access). If used more than one unary operator with the same operand, they must be in the order specified above, and are applied from right to left.


See also: pointer and reference variables, set dll function address



a = -b
if(c > -10) a = Func(-10 ~(d|e))
if(!win("Notepad")) out "Notepad window not found"
int* ip = &i
j = *ip
*ip = 10
POINT p; GetCursorPos(&p)