Contents hide 1) Datatypes In Go Programming 1.1) 1: Boolean 1.2) 2: String 1.3) 3: Integer 1.4) 4: Unsign Integer 1.5) 5: byte(unit8) 1.6) 6: rune (int32) 1.7) 7: float 1.8) 8: complex In this tutorial, we will see the various Datatypes In Go Programming Language such as: Boolean String Integer Uint Byte Rune Float Complex Datatypes In Go Programming 1: Boolean Very often, in programming, you will need a data type that can only have one of two values, like (YES / NO), (ON / OFF), (TRUE / FALSE) package main import "fmt" func main() { var a bool = true // Boolean VARIABLE DECLARATION IN GO var b bool = false if( a == b ) { // IF...ELSE CONDITION fmt.Printf("A And B Are Equal" ); } else { fmt.Printf("A And B Are Not Equal" ); } } OUTPUT C:\Users\rehmaanali\goWorkspace\src> go run hello.go A And B Are Not Equal 2: String GO Programming string type simply stores a series of characters like “Geeks Trick”. A string can be any text inside quotes. You can use double quotes only. package main import "fmt" func main() { var x string // STRING VARIABLE DECLARATION IN GO x = "Hello World, Let's Code GO!" //STRING fmt.Println(x) fmt.Printf("x is of type %T\n", x) // Display The Type Of Variable } OUTPUT C:\Users\rehmaanali\goWorkspace\src> go run hello.go Hello World, Let's Code GO! x is of type string 3: Integer In GO Programming language there are various types integers such as: int int8 int16 int32 int64 In Go programming int[size] this refers the bit size of the value. So how much data can be stored, how large integer it can store. And We have that one int which doesn’t have size So that ‘int’ is actually a type which will depend on the implementation so might depend on the architecture of the machine whether it’s a 32bit or 64bit machine. package main import "fmt" func main() { var x int32 // Will be 32bit integer value x = 20000000 fmt.Println(x) fmt.Printf("x is of type %T\n", x) // Display The Type Of Variable } OUTPUT C:\Users\rehmaanali\goWorkspace\src> go run hello.go 20000000 x is of type int32 4: Unsign Integer In GO Programming language there are various types unsign integers such as: uint uint8 uint16 uint32 uint64 uintptr In Go, programming uint are unsigned integers which are basically guaranteed to be a large enough to be a pointer or a reference to a memory address. package main import "fmt" func main() { var p uintptr = '\u0001' fmt.Println(p) fmt.Printf("p is of type %T\n", p) } OUTPUT C:\Users\rehmaanali\goWorkspace\src> go run hello.go 1 p is of type uintptr 5: byte(unit8) Here we also have a byte which is basically the same as an unsigned integer that is 8bit it mapped directly to that, you can exchange those types and those types are compatible. package main import "fmt" func main() { var b byte = 1.0 + 3i - 3.0i fmt.Println(b) fmt.Printf("b is of type %T\n", b) } OUTPUT C:\Users\rehmaanali\goWorkspace\src> go run hello.go 1 b is of type uint8 6: rune (int32) Same thing with the rune (int32) and if you think it’s like a character we can use rune in places where we have single symbols or may be using uni char character since GO supports the utf-8 and not just ask a character, the rune is going to be a type that you can utilize to do some interesting things in the language. package main import "fmt" func main() { var r rune = '\'' fmt.Println(r) fmt.Printf("r is of type %T\n", r) } OUTPUT C:\Users\rehmaanali\goWorkspace\src> go run hello.go 39 r is of type int32 7: float float32 float64 Then, of course, we have a float value, a 32bit and the 64bit. package main import "fmt" func main() { var f float64 = '\x01' fmt.Println(f) fmt.Printf("f is of type %T\n", f) } OUTPUT C:\Users\rehmaanali\goWorkspace\src> go run hello.go 1 f is of type float64 8: complex complex64 complex128 Go has support built in for complex numbers, so number that ends with an I imaginary numbers, you can do those in GO, a 64bit or 128bit package main import "fmt" func main() { var r complex64 = 'b' - 'a' fmt.Println(r) fmt.Printf("r is of type %T\n", r) } OUTPUT C:\Users\rehmaanali\goWorkspace\src> go run hello.go (1+0i) r is of type complex64 Get Some More GO Programming Here! Share this:TwitterFacebookRedditLinkedInWhatsAppPrintTumblr Related Tags: datatypes, go, go by google, go programming