Home  >  Article  >  Backend Development  >  How many bytes does int in golang occupy?

How many bytes does int in golang occupy?

尚
Original
2019-12-04 09:39:168298browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn