Go – Data Types

  • Post author:
  • Post category:GO
  • Post comments:1 Comment
Go - Data Types

This topic is about Go – Data Types.

In the Go programming language, data types refer to an extensive system used for declaring variables or functions of different types. The type of a variable determines how much space it occupies in storage and how the bit pattern stored is interpreted.

The types in Go can be classified as follows −

Sr.No.Types and Description
1Boolean typesThey are boolean types and consists of the two predefined constants: (a) true (b) false
2Numeric typesThey are again arithmetic types and they represents a) integer types or b) floating point values throughout the program.
3String typesA string type represents the set of string values. Its value is a sequence of bytes. Strings are immutable types that is once created, it is not possible to change the contents of a string. The predeclared string type is string.
4Derived typesThey include (a) Pointer types, (b) Array types, (c) Structure types, (d) Union types and (e) Function types f) Slice types g) Interface types h) Map types i) Channel Types

Array types and structure types are collectively referred to as aggregate types. The type of a function specifies the set of all functions with the same parameter and result types. We will discuss the basic types in the following section, whereas other types will be covered in the upcoming chapters.

Integer Types

The predefined architecture-independent integer types are −

Sr.No.Types and Description
1uint8Unsigned 8-bit integers (0 to 255)
2uint16Unsigned 16-bit integers (0 to 65535)
3uint32Unsigned 32-bit integers (0 to 4294967295)
4uint64Unsigned 64-bit integers (0 to 18446744073709551615)
5int8Signed 8-bit integers (-128 to 127)
6int16Signed 16-bit integers (-32768 to 32767)
7int32Signed 32-bit integers (-2147483648 to 2147483647)
8int64Signed 64-bit integers (-9223372036854775808 to 9223372036854775807)

Floating Types

The predefined architecture-independent float types are −

Sr.No.Types and Description
1float32IEEE-754 32-bit floating-point numbers
2float64IEEE-754 64-bit floating-point numbers
3complex64Complex numbers with float32 real and imaginary parts
4complex128Complex numbers with float64 real and imaginary parts

The value of an n-bit integer is n bits and is represented using two’s complement arithmetic operations.

Other Numeric Types

There is also a set of numeric types with implementation-specific sizes −

Sr.No.Types and Description
1bytesame as uint8
2runesame as int32
3uint32 or 64 bits
4intsame size as uint
5uintptran unsigned integer to store the uninterpreted bits of a pointer value

In this topic we learned about Go – Data Types. To know more, Click Here.

This Post Has One Comment

Leave a Reply