Go🔧Core Languagebeginner
Basic Types
Go · Core Language · Run with go run
Explanation
Go has a small, fixed set of built-in types. Integer types are explicitly sized (`int8`, `int16`, `int32`, `int64`, `uint8` … `uint64`), plus `int` and `uint` which are platform-width (64-bit on 64-bit systems). `string` is an immutable sequence of bytes (UTF-8). `rune` is an alias for `int32`, representing a Unicode code point.
Real-World Scenario
When reading binary protocols (e.g., network packets), you use `uint16` or `uint32` for wire-format fields to exactly match the spec — no overflow surprises.
Quick Snippet
snippet.go
var i int = 100
var u uint32 = 4294967295
var f float64 = 3.141592653589793
var b byte = 255 // alias for uint8
var r rune = '🚀' // alias for int32, holds Unicode code point
var s string = "Hello, 世界"
var ok bool = trueFull Example
basic_types.go
// Compile: go run basic_types.go
// Output:
// int: 100
// uint32: 4294967295
// float64: 3.141592653589793
// byte: 255
// rune: 128640 (🚀)
// string: Hello, 世界
// bool: true
package main
import "fmt"
func main() {
var i int = 100
var u uint32 = 4294967295
var f float64 = 3.141592653589793
var b byte = 255
var r rune = '🚀'
var s string = "Hello, 世界"
var ok bool = true
fmt.Println("int:", i)
fmt.Println("uint32:", u)
fmt.Println("float64:", f)
fmt.Println("byte:", b)
fmt.Printf("rune: %d (%c)\n", r, r)
fmt.Println("string:", s)
fmt.Println("bool:", ok)
}
Run command
go run basic_types.go