Composite types

Beside the basic types, there are others, which are known as composite types. These are as follows:

Type Description Example
Pointer The address in the memory of a variable *int
Array A container of the element of the same type with a fixed length [2]int
Slice Contiguous segment of an array []int
Map Dictionary or associative array map[int]int
Struct A collection of fields that can have different types struct{ value int }
Function A set of functions with the same parameters and output func(int, int) int
Channel Type pipes that are used for the communication of elements of the same type chan int
Interface A specific collection of methods, with an underlying value that supports them interface{}

 

The empty interface, interface{}, is a generic type that can contain any value. Since this interface has no requirements (methods), it can be satisfied by any value.

Interfaces, pointers, slices, functions, channels, and maps can have a void value, which is represented in Go by nil:

  • Pointers are self-explanatory; they are not referring to any variable address.
  • The interface's underlying value can be empty.
  • Other pointer types, like slices or channels, can be empty.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.20.224.107