Primitives

Contents

Primitives#

Type

Notes

bool

true or false. Not an integer; cannot be coerced.

int / int8 / int16 / int32 / int64

signed integers. int is platform-native width (32 or 64 bits).

uint / uint8 / uint16 / uint32 / uint64

unsigned integers.

uintptr

integer wide enough to hold a pointer; rarely needed.

byte

alias for uint8. Used for raw bytes.

rune

alias for int32. A Unicode code point.

float32 / float64

IEEE 754. float64 is the default.

complex64 / complex128

complex numbers; rare outside numerical code.

string

immutable UTF-8 byte sequence.

Variable declarations with explicit primitive types.

var n int = 42
var b byte = 0xff
var r rune = 'A'
var f float64 = 3.14
var s string = "operator"

References#

  • Strings for the byte vs rune distinction in depth.

  • Conversion for crossing between numeric types.