Golangbyte
Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Syntax and basics

  • Variables, Constants, and Data Types
    • Go types and conversion
// Signed integers
var a byte = 1
var b int8 = -127
var c int16 = 10240 // add one zero more to overflow var

// Unsigned integers
var f uint = 10000000000000000000 // uint32 + 1 byte for signed
var g uint8 = 255

// Complex Numbers
var l complex64 = 1 + 99i

// Floating Point numbers
var o float32 = 12.034

var n rune = 1220000000

// Constants
const pi = 3.14

// Type conversion
var a uint = 122
fmt.Println("a is ", a, reflect.TypeOf(a))
b := float32(a)
c := uintptr(a)
fmt.Println("b is ", b, reflect.TypeOf(b))
fmt.Println("c is ", b, reflect.TypeOf(c))