int), floating point numbers (float), characters (char), strings (string), and single-dimensional arrays.
3 + 5 6.7 + 23 "Hello " + "World" 5*3 + foobar()
When an expression contains values of different types, the two values are first cast to the same type, and then the operator applied. For example in the following expression:
5.7 + 8
The 8 is first cast to a float (8.0), and the two numbers are added (5.7 + 8.0). This becomes slightly more interesting when we use strings. For example:
"The result is " + (5 + 8)
5 is first added to 8, resulting in 13. The 13 is then converted to a string, and appended to "The result is " resulting in "The result is 13". However,
"The result is " + 5 + 8
would result in "The result is 58", since the the 5 is first converted to a string, then appended to "The result is "...
Of course, explicit casting is possible:
56 + (int)"7"
evaluates to 63.
The following operators are provided (in order of precedence, with associativity):
| Operator | Assoc | Description |
|---|---|---|
| = | right | assigns the value of the expression on the right to the variable on the left. |
| || | left | logical ‘or’, returns 0 if false, 1 if true |
| && | left | logical ‘and’ |
| == != < <= > >= | left | relational operators |
| + - | left | addition, subtraction |
| * / % | left | multiplication, division, modulus |
| - ! ++ -- | left | unary operators |
int, float, char, string, and single-dimensional arrays.
int x=5; is not yet legal).
for, while, do, break, continue, if, then, return.for requires a condition expression (i.e. for (;;) is not legal, instead, use for (;1;) or while (1))
include rather than #include
// My large applet
include "Part1"
include "Part2"
main() {
// call functions defined in other memos
}
str = "Here is a neat little square: " + (char)149;The other method is through using escape sequences. The following escape sequences are supported:
| Escape sequence | \\ | \' | \" | \n | \t | \x |
|---|---|---|---|---|---|---|
| Interpretation | \ | ' | " | newline | tab | character specified by the following two hex digits. Example: '\x95' is the block character (decimal 149) |