Go Data Types

Overview

Go is a statically typed language. Every variable has a specific type that is known at compile time.

var age int = 30
name := "GoLang"
price := 99.99
isActive := true

Basic Types

  • int, int8, int16, int32, int64
  • uint, uint8 (alias for byte), uint16, etc.
  • float32, float64
  • complex64, complex128
  • bool
  • string
  • rune (alias for int32, used for Unicode characters)

Default (Zero) Values

If a variable is declared without initialization, it gets a default zero value:

  • int0
  • boolfalse
  • string""
  • pointer/slice/map/function/interfacenil
var x int
var s string
fmt.Println(x) // 0
fmt.Println(s) // ""

Type Inference

When you use :=, Go automatically infers the type from the right-hand side:

a := 42          // int
b := 3.14        // float64
c := "hello"     // string
d := true        // bool

Type Conversion

Go does not allow implicit type casting — you must convert manually:

var i int = 42
var f float64 = float64(i)
var s string = fmt.Sprint(i)

Note: Conversion must be explicit even between compatible types like int32 and int64.

Aliases and Type Declarations

type declarations allow you to create new named types or type aliases for better readability, structure, and domain modeling in your programs

Loading...
Output:

This is useful when building clear domain-specific models.

Need Help?

Ask the AI if you need help understanding or want to dive deeper in any topic