GoLang Data Types String, Boolean, Numeric | GoLang Tutorial

5 years ago Lalit Bhagtani 0

In this tutorial, we will learn about primitive data types in Go programming language.

A data type represents the type of a value that can be stored in a variable or constant. Go programming language supports three different types of primitive data types. Golang data types are as follows :- 

  1. Boolean Type
  2. String Type
  3. Numeric Type

Boolean Type

A boolean type represents the set of two predefined constants true and false.

Example

var present bool 
var notpresent bool = false

String Type

A string type represents the set of string values. A string value is a sequence of bytes. Strings are immutable, that is once it is created, it is not possible to change the contents of a string.

Example

var name string 
var designation string = "Manager"

Numeric Type

A numeric type represents sets of integer, floating-point values.

Integer

The list of predefined integer types are as follows :-

S. No Name Description
1 uint8 Unsigned 8-bit integers (0 to 255)
2 uint16 Unsigned 16-bit integers (0 to 65535)
3 uint32 Unsigned 32-bit integers (0 to 4294967295)
4 uint64 Unsigned 64-bit integers (0 to 18446744073709551615)
5 int8 Signed 8-bit integers (-128 to 127)
6 int16 Signed 16-bit integers (-32768 to 32767)
7 int32 Signed 32-bit integers (-2147483648 to 2147483647)
8 int64 Signed 64-bit integers (-9223372036854775808 to 9223372036854775807)

Example

var age int16 
var number int64 = 123456

Float

The list of predefined floating point types are as follows :-

S. No Name Description
1 float32 IEEE-754 32-bit floating-point numbers
2 float64 IEEE-754 64-bit floating-point numbers
3 complex64 Complex numbers with float32 real and imaginary parts
4 complex128 Complex numbers with float64 real and imaginary parts

Example

var marks float32 
var average float64 = 16.5

References

  1. Boolean Type Docs
  2. Numeric Type Docs
  3. String Type Docs

That’s all for Golang data types, if you liked it, please share your thoughts in comments section and share it with others too.