Literals
Decimal Literals
421_000_000 // underscores for readabilityBase Prefixes
0xFF // hexadecimal: 2550b1010 // binary: 100o755 // octal: 493Underscores work with all bases:
0xFF_FF_FF_FF // 42949672950b1111_0000 // 240Integer Type Suffixes
Force a specific integer type with a trailing suffix:
42_i8 // int842_i16 // int1642_i32 // int3242_i64 // int64255_u8 // uint81000_u16 // uint160xFF_u32 // uint32100_nint // native int256_nuint // native uintFloat Literals
3.143.141_592_653 // underscores in floatsFloat Type Suffixes
3.14_f32 // float323.14_f64 // float6442_f32 // integer as float32Hex Float Literals
IEEE 754 hex float notation for exact representation:
0x1.0p0 // 1.00x1.0p1 // 2.0 (1.0 * 2^1)0x1.0p-1 // 0.50x1.8p0 // 1.50x1.0p0_f32 // float32String Escape Sequences
String literals support the following escape sequences:
| Escape | Character | Code Point |
|---|---|---|
\n | Newline | 10 |
\t | Tab | 9 |
\r | Carriage return | 13 |
\\ | Backslash | 92 |
\" | Double quote | 34 |
\0 | Null | 0 |
\b | Backspace | 8 |
\f | Form feed | 12 |
string msg = "Hello\nWorld"; // two linesstring path = "C:\\Users\\file"; // backslashesstring tab = "col1\tcol2"; // tab-separatedstring quoted = "She said \"hi\""; // embedded quotesCharacter Literals
Character literals evaluate to their integer code point:
'A' // 65'\n' // 10 (newline)'\t' // 9 (tab)'\\' // 92 (backslash)'\x41' // 65 (hex escape)'\xFF' // 255