Primitive types
Go's primitive types are the built-in scalars: booleans, integers, floating-point numbers, complex numbers, and strings. They are values, they copy on assignment, and they have no methods until you declare a named type on top of them.
Detailed Explanation
When you write var n int or name := "shop" you are using a primitive type. These types are part of the language, not a package. They occupy a known size, they compare with == (except that floats bring NaN rules), and they are the fields you put in structs.
Integers come in sized and platform kinds. int8 through int64 and uint8 through uint64 have fixed widths. int and uint are 32 bits on 32-bit platforms and 64 bits on 64-bit platforms — today's servers are 64. byte is an alias for uint8. rune is an alias for int32 and holds a Unicode code point. uintptr holds a pointer bit pattern for unsafe code; it is not a pointer. Integer overflow wraps silently in Go; it does not panic.
There is no implicit numeric conversion. var n int; var m int64 = n does not compile. You write int64(n). Conversion between integer types that lose range is allowed and truncates. Conversion between integers and floats is allowed and may lose precision. Conversion between unrelated types (int to string) is a different meaning: string(65) is "A", not "65". Use strconv for decimal text.
Floats are float32 and float64. An untyped decimal constant such as 1.0 defaults to float64. float32 is for storage and interchange; compute in float64 unless you have a measured reason. complex64 and complex128 exist and are rarely needed outside numerics.
bool is its own type. There is no conversion from int to bool. if n { does not compile.
string is an immutable sequence of bytes. It is a primitive in the language sense: assignment copies the header (pointer plus length), the bytes are shared, and you cannot mutate them. Ranging a string yields runes, indexing a string yields bytes. An empty string is "", not nil.
What it costs. int arithmetic is what the CPU does. string concatenation with + allocates a new backing array. Sized integers matter when you serialize a struct or talk to a C API; using int in a file format is a portability bug. Prefer int for slice indexes and counts, and sized types for on-the-wire and on-disk layouts.
Code Examples
package main
import "fmt"
func main() {
var n int = 42
var wide int64 = int64(n) // conversion is required
var flag bool = n > 0
var name string = "shop"
fmt.Println(wide, flag, name)
}func bits() {
var u uint8 = 255
u++ // wraps to 0; no panic
var r rune = '€' // code point, not a byte
var b byte = 'A' // alias of uint8
fmt.Println(u, r, b)
}func text() {
s := "Go"
fmt.Println(s[0]) // 71, a byte
fmt.Println(string(65)) // A — not "65"
}Common Gotchas
Mixed integer types do not combine
`int + int64` is a compile error. Convert one side.
`string(n)` for an integer `n` is a conversion to a one-rune string, not a decimal
use `strconv.Itoa`.
`int` is not a file-format type
a struct you encode as binary should use `int32` or `int64` so 32-bit and 64-bit processes agree.
`byte` and `rune` are aliases
they convert to `uint8` and `int32` without a cast in some contexts because they are the same underlying type, but named types you define on top of `int` do not.