Data types in Go can be categorized into the following groups:
-
Basic Types:
- Boolean type:
bool(values aretrueorfalse) - Numeric types:
- Integer types:
int,int8,int16,int32,int64,uint,uint8,uint16,uint32,uint64,uintptr - Floating-point types:
float32,float64 - Complex types:
complex64,complex128
- Integer types:
- String type:
string
- Boolean type:
-
Composite Types:
- Array type: Declares a sequence of elements with a fixed size and type, e.g.,
var a [5]int - Slice type: A dynamic-size version of arrays where the length is not specified at declaration, e.g.,
var b []int - Struct type:
struct, which organizes different data types into a composite entity, e.g.,gotype Person struct { Name string Age int } - Pointer type: Used to store the memory address of a variable, e.g.,
var p *int
- Array type: Declares a sequence of elements with a fixed size and type, e.g.,
-
Special Types:
- Interface type:
interface, which defines a set of method signatures but does not implement them; other types implement these methods, e.g.,gotype Shape interface { Area() float64 Perimeter() float64 } - Map type:
map, which stores key-value pairs where keys and values can be of different types, e.g.,var m map[string]int
- Interface type:
-
Channel type (
chan): Used for communication between multiple Go goroutines, e.g.,chan int
Various data types support Go's powerful concurrency model and memory safety features, making it well-suited for systems programming and high-performance application development.