NXC  Version 1.2.1 r5
 All Data Structures Files Functions Variables Groups Pages

Values are the most primitive type of expressions.

More complicated expressions are formed from values using various operators.

Numerical constants in the NXT are represented as integers or floating point values. The type depends on the value of the constant. NXC internally uses 32 bit floating point math for constant expression evaluation. Numeric constants are written as either decimal (e.g. 123, 3.14) or hexadecimal (e.g. 0xABC). Presently, there is very little range checking on constants, so using a value larger than expected may produce unusual results.

Two special values are predefined: true and false. The value of false is zero (0), while the value of true is one (1). The same values hold for relational operators (e.g. <): when the relation is false the value is 0, otherwise the value is 1.

Values may be combined using operators. NXC operators are listed here in order of precedence from highest to lowest.

abs()Absolute valuen/a abs(x)
sign()Sign of operandn/a sign(x)
++, –Postfix increment/decrementleftvariables onlyx++
++, –Prefix increment/decrementrightvariables only++x
-Unary minusright -x
~Bitwise negation (unary)right ~123
!Logical negationright !x
*, /, %Multiplication, division, modulusleft x * y
+, -Addition, subtractionleft x + y
<<, >>Bitwise shift left and rightleft x << 4
<, >, <=, >=relational operatorsleft x < y
==, !=equal to, not equal toleft x == 1
&Bitwise ANDleft x & y
^Bitwise exclusive ORleft x ^ y
|Bitwise inclusive ORleft x | y
&&Logical ANDleft x && y
||Logical ORleft x || y
?:Ternary conditional valueright x==1 ? y : z
Table 5. Expression Operators

Where needed, parentheses are used to change the order of evaluation:

x = 2 + 3 * 4; // set x to 14
y = (2 + 3) * 4; // set y to 20