Go - Types & Keywords

Beginner 10/10 Teacher 10/10 Architect 10/10

Built-in Types

  • Numbers: int, int64, float64, complex128
  • Text: string, rune (Unicode code point), byte
  • Aggregates: array, slice, map, struct
  • Others: bool, pointer, interface

Zero Values and Inference

var s string // ""
var n int    // 0
var f float64 // 0
var b bool   // false
x := 10      // inferred int

Important Keywords

  • defer, panic, recover
  • go (start goroutine), select
  • type, interface

Common errors

  • Mixed types in expressions without explicit conversion (e.g., int + float64). Fix by converting: float64(i) + f.
  • Using := at package level. Short declaration only works inside functions.

Practice

  • Declare variables of types int, float64, and string, then print them with fmt.Printf using verbs %d, %f, and %q.
  • Convert an int to float64 and add it to another float64 number.

Quick quiz

  1. What’s the zero value of string?
  2. When can you use :=?
Show answers
  1. An empty string ("").
  2. Inside functions when declaring a new variable.