Go Data Types

Go (Golang) – Data Types

Go is a statically typed language, meaning every variable has a specific data type known at compile time. Go data types are broadly divided into basic, composite, and derived types.


1️⃣ Basic Data Types

🔹 Integer Types

Type Size Description
int 32/64-bit Platform dependent
int8 8-bit −128 to 127
int16 16-bit −32,768 to 32,767
int32 32-bit Unicode / rune
int64 64-bit Large numbers
uint 32/64-bit Unsigned integer
uint8 8-bit Alias: byte
uint16 16-bit
uint32 32-bit
uint64 64-bit
var age int = 25
var count uint8 = 255

🔹 Floating-Point Types

Type Size
float32 32-bit
float64 64-bit (default)
var price float64 = 99.99

🔹 Complex Types

Type Description
complex64 float32 real + imag
complex128 float64 real + imag
c := complex(3, 4)

🔹 Boolean Type

var isActive bool = true

🔹 String Type

var name string = "GoLang"

✔ UTF-8 encoded
✔ Immutable


2️⃣ Composite Data Types

🔹 Arrays (Fixed Size)

var nums [3]int = [3]int{1, 2, 3}

🔹 Slices (Dynamic)

numbers := []int{1, 2, 3}
numbers = append(numbers, 4)

🔹 Maps (Key–Value Pair)

student := map[string]int{
"Math": 90,
"Sci": 85,
}

🔹 Structs (User-defined Type)

type User struct {
Name string
Age int
}

3️⃣ Derived Data Types

🔹 Pointers

x := 10
ptr := &x

🔹 Functions as Types

var add func(int, int) int

🔹 Interfaces

type Shape interface {
Area() float64
}

4️⃣ Special Types

Type Description
byte Alias for uint8
rune Alias for int32 (Unicode)
uintptr Pointer arithmetic
nil Zero value for reference types

5️⃣ Type Conversion (Not Automatic)

❌ Invalid:

var a int = 10
var b float64 = a // error

✅ Valid:

var b float64 = float64(a)

6️⃣ Checking Data Type

fmt.Printf("%T\n", name)

Summary

  • Go has strong & static typing

  • No implicit type conversion

  • Supports basic, composite & derived types

  • UTF-8 string support built-in

You may also like...