(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:
v is byte type: In define (1.2), the initial value of v must less 255. (var v byte = 12)
s[i] always less then 255 in for loop s[i] = v + byte(i).
Readability is key here. So it makes sense to declare a statement close to where it is first used, and limit it to the smallest possible scope where it is needed.
the location of the variable declaration makes no difference at run time.
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:
Note:
v
is byte type: In define (1.2), the initial value ofv
must less 255. (var v byte = 12
)s[i]
always less then 255 in for loops[i] = v + byte(i)
.const N
make stack overflow, see link3. Ref