乐闻世界logo
搜索文章和话题

What Data Types Does Go Use?

2月7日 13:45

Go uses the following data types:

  1. Basic Types:
  • Boolean type: bool
  • Integer types: int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, uintptr
  • Floating-point types: float32, float64
  • Complex types: complex64, complex128
  • String: string
  1. Composite Types:
  • Arrays: Defined as var a [5]int
  • Slices: Dynamic arrays, defined as var s []int
  • Structs: Used to define and group data of different or same types, for example type Person struct { Name string; Age int }
  • Pointers: Store memory addresses of variables, defined as var p *int
  • Function types: Functions can be passed as values, for example func add(x, y int) int { return x + y }
  • Interfaces: Define types with method sets, for example type Geometry interface { Area() float64; Perimeter() float64 }
  • Maps: Collections of key-value pairs, defined as var m map[string]int
  • Channels: Used for communication between multiple Go goroutines, defined as ch := make(chan int)

Using these data types, you can build and manage data structures, enabling modular functionality and concise code.

标签:Golang