How many bytes does int in golang occupy?

Release: 2019-12-04 09:39:16
Original
8360 people have browsed it

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}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template