How to find size of datatypes in Golang 1.20

Channel:
Subscribers:
5,740
Published on ● Video Link: https://www.youtube.com/watch?v=pdg8CdUuvWA



Category:
Tutorial
Duration: 2:20
2 views
0


In this video we are going to generate source code for the GoLang Program, How to find size of datatypes using chatGPT.
After generating we will verify and run the generated code.

IMPORTANT NOTE on SOURCE CODE: only source code that are acceptable by the youtube description box will be displayed.



##############SOURCE CODE#########################

package main

import (
"fmt"
"unsafe"
)

func main() {
fmt.Printf("Size of int8: %d byte(s)\n", unsafe.Sizeof(int8(0)))
fmt.Printf("Size of int16: %d byte(s)\n", unsafe.Sizeof(int16(0)))
fmt.Printf("Size of int32: %d byte(s)\n", unsafe.Sizeof(int32(0)))
fmt.Printf("Size of int64: %d byte(s)\n", unsafe.Sizeof(int64(0)))
fmt.Printf("Size of uint8: %d byte(s)\n", unsafe.Sizeof(uint8(0)))
fmt.Printf("Size of uint16: %d byte(s)\n", unsafe.Sizeof(uint16(0)))
fmt.Printf("Size of uint32: %d byte(s)\n", unsafe.Sizeof(uint32(0)))
fmt.Printf("Size of uint64: %d byte(s)\n", unsafe.Sizeof(uint64(0)))
fmt.Printf("Size of float32: %d byte(s)\n", unsafe.Sizeof(float32(0)))
fmt.Printf("Size of float64: %d byte(s)\n", unsafe.Sizeof(float64(0)))
fmt.Printf("Size of bool: %d byte(s)\n", unsafe.Sizeof(false))
fmt.Printf("Size of string: %d byte(s)\n", unsafe.Sizeof(""))
}

##############END OF SOURCE CODE#########################

Below is the explanation for the program:

The program uses the unsafe.Sizeof function from the unsafe package to find the size in bytes of various data types. The program prints the size of the following data types:

int8
int16
int32
int64
uint8
uint16
uint32
uint64
float32
float64
bool
string
You can modify the program to include any other data types you're interested in.


#go #goprogramming #golang #golangtutorial #golanguage







Tags:
how to print size of datatype using sizeof in golang
go program to print the size of type using sizeof operator
sizeof in go
datatype size in go
go Programming Tutorial
go by example
go Language
go projects
go programming projects
go tutorial
golang tutorial
golang projects
go programming course
learn go
how to run go program
golang videos
golang with chatgpt
coding questions
coding interview questions