Sambar Server Documentation
|
CScript Operators |
So, for example, '
= assignment += addition assignment -= subtraction assignment *= multiplication assignment /= division assignment %= remainder/modulus assignment &= bitwise AND assignment |= bitwise OR assignment ^= bitwise exclusive OR assignment <<= left shift assignment >>= right shift assignment
i += j
' is equivalent to
'i = i + j
' (see complete list of equivalents below).
The value to the left of the assignment operator has to be a variable where
a result can be stored.
Unless parens are used to order evaluation, operator precedence specifies that *, / and % be performed before + or - in an expression. The following table shows the precedence of all operators:
+ Addition - Subtraction * Multiplication / Division % Modulo (remainder from integer division) + Addition
Note:
Operator Associativity Description ( ) left-to-right Parenthesis ! ~ ++ -- - * & right-to-left Unary * / % left-to-right Multiply, Divide Modulus + - left-to-right Add, Subtract >> << left-to-right Shift Right, Left > < = left-to-right Greater, Less Than == != left-to-right Equal, Not Equal & left-to-right Bitwise AND ^ left-to-right Bitwise Exclusive OR | left-to-right Bitwise OR && left-to-right Logical AND || left-to-right Logical OR ?: right-to-left Conditional Expression = += -= etc. right-to-left Assignment , left-to-right Comma
C has some operators which allow abbreviation of certain types of arithmetic assignment statements.
For auto-increment (++) and decrement (--), if the operator occurs before the variable name (i.e. --i;) change the value of the variable before evaluating the remainder of the expression:
Shorthand Equivalent i++; i = i + 1; ++i; i = i + 1; i--; i = i - 1; --i; i = i - 1; a += 22; a = a + 22; a -= 22; a = a - 22; a *= 22; a = a * 22; a /= 22; a = a / 22; a %= 22; a = a % 22;
Shorthand Equivalent a = i-- * b; a = i * b;
i = i - i;a = --i * b; i = i - 1;
a = i * b
sizeof(i) the number of bytes of storage allocated to i +123 positive 123 -123 negative 123 ~i one's complement (bitwise complement) !i logical negation (i.e., 1 if i is zero, 0 otherwise) *i returns the value stored at the address pointed to by i NOT SUPPORTED! &i returns the address in memory of i ++i adds one to i, and returns the new value of i --i subtracts one from i, and returns the new value of i i++ adds one to i, and returns the old value of i i-- subtracts one from i, and returns the old value of i i[j] array indexing i (j) calling the function i with argument j i.j returns member j of structure i NOT SUPPORTED! i->j returns member j of structure pointed to by i NOT SUPPORTED!
x = x & 0177;forms the bit-wise AND of x and 0177, effectively retaining only the last seven bits of x. Other operators are:
Operator Description | inclusive OR ^ exclusive OR ~ 1's complement ! logical not << left shift >> right shift
The comma operator has the lowest precedence, so it is always executed last when evaluating an expression. Both of the above examples are artifical, and not very useful. The comma operator can be useful when used in for and while loops.
Shorthand Equivalent i = ((j = 2), 3); i = 3; j = 2; myfunct (i, (j = 2, j + 1), 1); j = 2; myfunct (i, 3, 1);
© 2001 Sambar Technologies. All rights reserved. Terms of Use.