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

Once declared, variables may be assigned the value of an expression using the syntax shown in the code sample below.

variable assign_operator expression;

There are thirteen different assignment operators. The most basic operator, '=', simply assigns the value of the expression to the variable. The other operators modify the variable's value in some other way as shown in the table below.

=Set variable to expression
+=Add expression to variable
-=Subtract expression from variable
*=Multiple variable by expression
/=Divide variable by expression
%=Set variable to remainder after dividing by expression
&=Bitwise AND expression into variable
|=Bitwise OR expression into variable
^=Bitwise exclusive OR into variable
||=Set variable to absolute value of expression
+-=Set variable to sign (-1,+1,0) of expression
>>=Right shift variable by expression
<<=Left shift variable by expression
Table 3. Operators

The code sample below shows a few of the different types of operators that you can use in NXC expressions.

x = 2; // set x to 2
y = 7; // set y to 7
x += y; // x is 9, y is still 7