Skip to content

Instantly share code, notes, and snippets.

@sahajre
Created August 18, 2019 13:47
Show Gist options
  • Save sahajre/1d633d9bc9c4f459506107e4b07858c2 to your computer and use it in GitHub Desktop.
Save sahajre/1d633d9bc9c4f459506107e4b07858c2 to your computer and use it in GitHub Desktop.
package main
import "fmt"
func main() {
var i int
var i8 int8
var i16 int16
var i32 int32
var i64 int64
var u uint
var u8 uint8
var u16 uint16
var u32 uint32
var u64 uint64
var uptr uintptr
var f32 float32
var f64 float64
var c64 complex64
var c128 complex128
fmt.Println("numeric types (int/uint/uintptr/float/complex):", i, i8, i16, i32, i64, u, u8, u16, u32, u64, uptr, f32, f64, c64, c128)
var r rune // alias for int32, represents a unicode code point
fmt.Println("rune:", r)
var b byte // alias for uint8
fmt.Println("byte:", b)
var bl bool
fmt.Println("boolean:", bl)
var s string
fmt.Println("string:", s, "(an empty string)")
var e error
fmt.Println("error:", e)
var p *int
fmt.Println("pointer:", p)
var ch chan string
fmt.Println("channel:", ch)
var fn func()
fmt.Println("func:", fn)
var iface interface{}
fmt.Println("interface:", iface)
var m map[string]int
fmt.Println("map:", m)
fmt.Println("map variable compared to nil, i.e m == nil: ", m == nil)
var sl []int
fmt.Println("slice:", sl)
fmt.Println("slice variable compared to nil, i.e sl == nil: ", sl == nil)
var arrInt [5]int
fmt.Println("array of 5 ints:", arrInt)
var arrBool [5]bool
fmt.Println("array of 5 bools:", arrBool)
var arrStr [5]string
fmt.Println("array of 5 strings:", arrStr, "(an array of 5 empty strings)")
}
/* Output:
numeric types (int/uint/uintptr/float/complex): 0 0 0 0 0 0 0 0 0 0 0 0 0 (0+0i) (0+0i)
rune: 0
byte: 0
boolean: false
string: (an empty string)
error: <nil>
pointer: <nil>
channel: <nil>
func: <nil>
interface: <nil>
map: map[]
map variable compared to nil, i.e m == nil: true
slice: []
slice variable compared to nil, i.e sl == nil: true
array of 5 ints: [0 0 0 0 0]
array of 5 bools: [false false false false false]
array of 5 strings: [ ] (an array of 5 empty strings)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment