Primitive Types and Type Conversion

5.1 Types

i8, i16, int (32-bit), i32 (= int), i64, isize u8 (byte), u16, u32, u64, usize

string (immutable UTF-8 bytes), rune (Unicode code point, = i32)

voidptr, &T, charptr/byteptr (C interop) any (limited), thread T, chan T

Note: In V, int is always 32-bit (it may become 64-bit on 64-bit platforms in future versions; check the docs). Use i64 for large values.

5.2 Literals

dec := 1_000_000
hex := 0xFF
oct := 0o17
bin := 0b1010
f := 3.14
e := 1e-3
ch := `A`                 // rune literal (backticks)
s := 'single quotes preferred'
s2 := "double quotes also work"
raw := r'C:\no\escapes'
c_str := c'hello'         // C string literal (&char)

5.3 Zero Values

int/f64 → 0, bool → false, string → '', arrays → [], maps → {}, structs → each field's zero value, options → none.

5.4 Type Conversion (Always Explicit)

Integer promotion happens automatically to wider types of the same signedness (i8 → int). There's no implicit int ↔ float conversion.

x := 10
f := f64(x) / 3          // explicit cast
i := int(3.99)           // 3
b := u8(255)
s := x.str()             // to string
n := '42'.int()          // string → int (returns 0 on failure)
p := '3.14'.f64()
safe := strconv.atoi('42')!   // returns a result: errors on invalid input
println(typeof(x).name)
println(sizeof(int))