Type casting

suggest change

Unlike a language like C, Go doesn’t do implicit casting between types.

You have to explicitly cast between compatible types:

// you can cast between numbers i.e. integers of various sizes and floating point numbers
var i1 int32 = 3
var i2 int = int(i1) // we must explicitly cast from int32 to int
var f float64 = float64(i1)

s := "string"
// we can cast between string and []byte and vice-versa
// note that unless optimizted by the compiler, this involves allocation
var d []byte = []byte(s)

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents