Home > Article > Backend Development > How many bytes does int in golang occupy?
int is a signed integer type whose size is at least 32 bits. It's an exact type, not an alias for int32. (Recommended: go video tutorial)
int is not int32, how many bytes does int occupy in the memory? It’s not official yet, let’s test it.
GOARCH="amd64"
package mainimport ( "fmt" "unsafe" )func main() { i := int(1) fmt.Println(unsafe.Sizeof(i)) // 4 j := 1 fmt.Println(unsafe.Sizeof(j)) // 4 u := uint(1) fmt.Println(unsafe.Sizeof(u)) // 4}
Can it be considered that int is 4 bytes? I dare not think so, GoLang supports multiple platform architectures. If there are clear requirements for size, then use int32 or the like.
Supplement: As the Go version changes, this is indeed changing, so how many bytes it occupies depends on the specific version
For more golang knowledge, please pay attention togolang tutorial column.
The above is the detailed content of How many bytes does int in golang occupy?. For more information, please follow other related articles on the PHP Chinese website!