mtchuyen / Golang-Tips

Tips in Golang programming
3 stars 2 forks source link

Golang byte type and variable #13

Open mtchuyen opened 2 years ago

mtchuyen commented 2 years ago

1. Byte type

(1). A byte in Go is an unsigned 8-bit integer. It has type uint8.

(2). A byte has a limit of 0 – 255 in numerical range.

(3). It can represent an ASCII character.

2. Sampe code:

package main

import (
    "fmt"
)

const N = 512 * 1024 * 1024 // 500M
const M = 123

var v byte = 12

func main() {
    fmt.Println("Hello, playground")

    var s = []byte{N: 0}
    for i := range s {
        s[i] = v + byte(i)
        println(i, s[i])
    }
}

Note:

3. Ref

mtchuyen commented 2 years ago

variable

The best position of variable declarations: