byte
type in GolangThe byte
type in Golang is an alias for the unsigned integer 8 type (uint8
). The byte
type is only used to semantically distinguish between an unsigned integer 8 and a byte. The range of a byte
is 0
to 255
(same as uint8
).
byte
typeThe following example demonstrates the use of byte
type:
package mainimport "fmt"func main() {var a byte = 100var b byte = 'B'fmt.Println(a)fmt.Println(b)}
In the example above, both variables a
and b
are of byte
type. In the variable a
, we store an integer 100
, and in variable b
, we store a character B
. Both these variables result in an integer value being printed onto the standard output. In the case of variable b
, the ASCII value of B
, which is 66
, is printed.
Free Resources