Data Types (int, float, string, bool, etc.) in Go

List Topics
February 15, 2025
No Comments
3 min read

Go Data Types: Detailed Explanation

In Go, data types define the type of data a variable can hold. Go is a statically typed language, meaning the type of a variable is determined at compile time.

1. Basic Data Types in Go

TypeDescriptionExample
boolBoolean (true/false)var isGoAwesome bool = true
stringSequence of charactersvar language string = "Go"
intInteger numbers (size depends on system)var age int = 25
float32 / float64Floating-point numbersvar pi float64 = 3.1416
complex64 / complex128Complex numbersvar c complex128 = 1 + 2i
byteAlias for uint8 (unsigned 8-bit integer)var b byte = 255
runeAlias for int32 (used for Unicode characters)var r rune = 'G'

2. Integer Data Types

Go provides different integer types based on size:

TypeSize (bits)Value Range
int88-bit-128 to 127
int1616-bit-32,768 to 32,767
int3232-bit-2,147,483,648 to 2,147,483,647
int6464-bit-9 quintillion to 9 quintillion
uint88-bit0 to 255
uint1616-bit0 to 65,535
uint3232-bit0 to 4,294,967,295
uint6464-bit0 to 18 quintillion

🔹 int and uint are system-dependent (either 32-bit or 64-bit).

3. Floating-Point Data Types

TypeSize (bits)Precision
float3232-bit6-7 decimal places
float6464-bit15-16 decimal places

🔹 float64 is preferred in Go for accuracy.

4. Complex Number Data Types

Go supports complex numbers:

Go
var c1 complex64 = 1 + 2i
var c2 complex128 = 3.5 + 4.5i

🔹 complex64 uses float32, while complex128 uses float64 for real and imaginary parts.

5. String Data Type

Strings in Go are UTF-8 encoded and immutable.

Go
var message string = "Hello, Go!"
fmt.Println(message)

🔹 Strings can be concatenated using +.

6. Boolean Data Type

Booleans hold true or false values.

Go
var isGoEasy bool = true
fmt.Println(isGoEasy)

🔹 Default value is false.

7. Derived Data Types

TypeDescription
arrayFixed-length collection of elements of the same type
sliceDynamically sized array
mapKey-value pair collection (like dictionaries in Python)
structCustom data structure
pointerStores memory address of a variable
interfaceDefines a set of method signatures

Example: Using Different Data Types in Go

Go
package main

import "fmt"

func main() {
    var name string = "Go"
    var version float64 = 1.22
    var isStable bool = true
    var users int = 5000000
    var letter rune = 'G'

    fmt.Println("Language:", name)
    fmt.Println("Version:", version)
    fmt.Println("Is Stable:", isStable)
    fmt.Println("Number of Users:", users)
    fmt.Println("First Letter:", letter)
}

Go Data Types āĻŦā§āϝāĻžāĻ–ā§āϝāĻž

Go-āϤ⧇ āĻĄāĻžāϟāĻž āϟāĻžāχāĻĒ āύāĻŋāĻ°ā§āϧāĻžāϰāĻŖ āĻ•āϰ⧇ āϝ⧇ āĻāĻ•āϟāĻŋ āϭ⧇āϰāĻŋāϝāĻŧ⧇āĻŦāϞ āϕ⧀ āϧāϰāύ⧇āϰ āĻĄāĻžāϟāĻž āϏāĻ‚āϰāĻ•ā§āώāĻŖ āĻ•āϰāϤ⧇ āĻĒāĻžāϰāĻŦ⧇āĨ¤ Go āĻāĻ•āϟāĻŋ statistically typed āĻ­āĻžāώāĻž, āĻ…āĻ°ā§āĻĨāĻžā§Ž āĻ•āĻŽā§āĻĒāĻžāχāϞ āϟāĻžāχāĻŽā§‡ āĻĄāĻžāϟāĻž āϟāĻžāχāĻĒ āύāĻŋāĻ°ā§āϧāĻžāϰāĻŖ āĻšāϝāĻŧāĨ¤

ā§§. āĻŽā§ŒāϞāĻŋāĻ• (Basic) āĻĄāĻžāϟāĻž āϟāĻžāχāĻĒ

āϟāĻžāχāĻĒāĻŦāĻ°ā§āĻŖāύāĻžāωāĻĻāĻžāĻšāϰāĻŖ
boolāϏāĻ¤ā§āϝ/āĻŽāĻŋāĻĨā§āϝāĻž (Boolean)var isGoAwesome bool = true
stringāĻŸā§‡āĻ•ā§āϏāϟ āĻĄāĻžāϟāĻžvar language string = "Go"
intāĻĒā§‚āĻ°ā§āĻŖāϏāĻ‚āĻ–ā§āϝāĻž (Integer)var age int = 25
float32 / float64āĻĻāĻļāĻŽāĻŋāĻ• āϏāĻ‚āĻ–ā§āϝāĻž (Floating-point)var pi float64 = 3.1416
complex64 / complex128āĻ•āĻŽāĻĒā§āϞ⧇āĻ•ā§āϏ āϏāĻ‚āĻ–ā§āϝāĻžvar c complex128 = 1 + 2i
byteuint8 āĻāϰ āϏāĻŽāϤ⧁āĻ˛ā§āϝvar b byte = 255
runeint32 āĻāϰ āϏāĻŽāϤ⧁āĻ˛ā§āϝ (āχāωāύāĻŋāϕ⧋āĻĄ āĻ•ā§āϝāĻžāϰ⧇āĻ•ā§āϟāĻžāϰ)var r rune = 'G'

⧍. āĻĒā§‚āĻ°ā§āĻŖāϏāĻ‚āĻ–ā§āϝāĻž (Integer) āϟāĻžāχāĻĒāϏāĻŽā§‚āĻš

āϟāĻžāχāĻĒāϏāĻžāχāϜ (āĻŦāĻŋāϟ)āĻŽāĻžāύ⧇āϰ āĻĒāϰāĻŋāϏ⧀āĻŽāĻž
int88-bit-128 āĻĨ⧇āϕ⧇ 127
int1616-bit-32,768 āĻĨ⧇āϕ⧇ 32,767
int3232-bit-2,147,483,648 āĻĨ⧇āϕ⧇ 2,147,483,647
int6464-bit-9 āϕ⧋āϝāĻŧāĻžāĻĄā§āϰāĻŋāϞāĻŋāϝāĻŧāύ āĻĨ⧇āϕ⧇ 9 āϕ⧋āϝāĻŧāĻžāĻĄā§āϰāĻŋāϞāĻŋāϝāĻŧāύ
uint88-bit0 āĻĨ⧇āϕ⧇ 255
uint1616-bit0 āĻĨ⧇āϕ⧇ 65,535
uint3232-bit0 āĻĨ⧇āϕ⧇ 4,294,967,295
uint6464-bit0 āĻĨ⧇āϕ⧇ 18 āϕ⧋āϝāĻŧāĻžāĻĄā§āϰāĻŋāϞāĻŋāϝāĻŧāύ

ā§Š. āĻĻāĻļāĻŽāĻŋāĻ• āϏāĻ‚āĻ–ā§āϝāĻž (Floating-Point) āϟāĻžāχāĻĒāϏāĻŽā§‚āĻš

āϟāĻžāχāĻĒāϏāĻžāχāϜ (āĻŦāĻŋāϟ)āύāĻŋāĻ°ā§āϭ⧁āϞāϤāĻž
float3232-bit6-7 āĻĻāĻļāĻŽāĻŋāĻ• āĻ¸ā§āĻĨāĻžāύ
float6464-bit15-16 āĻĻāĻļāĻŽāĻŋāĻ• āĻ¸ā§āĻĨāĻžāύ

🔹 Go-āϤ⧇ float64 āĻŦ⧇āĻļāĻŋ āύāĻŋāĻ°ā§āϭ⧁āϞ āĻšāĻ“āϝāĻŧāĻžāϰ āϜāĻ¨ā§āϝ āĻŦ⧇āĻļāĻŋ āĻŦā§āϝāĻŦāĻšā§ƒāϤ āĻšāϝāĻŧāĨ¤

ā§Ē. āĻ¸ā§āĻŸā§āϰāĻŋāĻ‚ (String) āϟāĻžāχāĻĒ

Go-āϤ⧇ āĻ¸ā§āĻŸā§āϰāĻŋāĻ‚ āχāĻŽāĻŋāωāĻŸā§‡āĻŦāϞ (āĻĒāϰāĻŋāĻŦāĻ°ā§āϤāύ āĻ•āϰāĻž āϝāĻžāϝāĻŧ āύāĻž)āĨ¤

Go
var message string = "Hello, Go!"
fmt.Println(message)

ā§Ģ. āĻŦ⧁āϞāĻŋāϝāĻŧāĻžāύ (Boolean) āϟāĻžāχāĻĒ

Go
var isGoEasy bool = true
fmt.Println(isGoEasy)

🔹 āĻĄāĻŋāĻĢāĻ˛ā§āϟ āĻŽāĻžāύ false āĻšāϝāĻŧāĨ¤

ā§Ŧ. āĻĄā§‡āϰāĻžāχāĻ­āĻĄ (Derived) āĻĄāĻžāϟāĻž āϟāĻžāχāĻĒāϏāĻŽā§‚āĻš

āϟāĻžāχāĻĒāĻŦāĻ°ā§āĻŖāύāĻž
arrayāĻāĻ•āχ āϧāϰāύ⧇āϰ āωāĻĒāĻžāĻĻāĻžāύ⧇āϰ āύāĻŋāĻ°ā§āĻĻāĻŋāĻˇā§āϟ āφāĻ•āĻžāϰ⧇āϰ āϏāĻ‚āĻ—ā§āϰāĻš
sliceāĻĒāϰāĻŋāĻŦāĻ°ā§āϤāύāĻļā§€āϞ āφāĻ•āĻžāϰ⧇āϰ āĻ…ā§āϝāĻžāϰ⧇
mapāϕ⧀-āĻ­ā§āϝāĻžāϞ⧁ āĻĒ⧇āϝāĻŧāĻžāϰ āĻĄāĻžāϟāĻž āĻ¸ā§āĻŸā§āϰāĻžāĻ•āϚāĻžāϰ
structāĻ•āĻžāĻ¸ā§āϟāĻŽ āĻĄāĻžāϟāĻž āĻ¸ā§āĻŸā§āϰāĻžāĻ•āϚāĻžāϰ
pointerāĻŽā§‡āĻŽā§‹āϰāĻŋ āĻ āĻŋāĻ•āĻžāύāĻž āϏāĻ‚āϰāĻ•ā§āώāĻŖāĻ•āĻžāϰ⧀ āϟāĻžāχāĻĒ
interfaceāĻŽā§‡āĻĨāĻĄ āĻĄā§‡āĻĢāĻŋāύāĻŋāĻļāύ⧇āϰ āϜāĻ¨ā§āϝ āĻŦā§āϝāĻŦāĻšā§ƒāϤ āĻšāϝāĻŧ

Š2025 Linux Bangla | Developed & Maintaind by Linux Bangla.