data types Flashcards
(8 cards)
bool
Values: true or false
Zero Value: false
Example:
go
var isReady bool = true
Signed Integers
int: Platform-dependent (32/64-bit)
int8: 8-bit (-128 to 127)
int16: 16-bit (-32,768 to 32,767)
int32: 32-bit (-2.1B to 2.1B)
int64: 64-bit
Zero Value: 0
Example:
go
var age int = 30
byte
Alias for: uint8 (0 to 255)
Use Case: Raw binary data (e.g., file/network streams).
Example:
go
var b byte = ‘A’ // ASCII 65
Unsigned Integers
uint: Platform-dependent (32/64-bit)
**uint8/byte: 0 to 255
uint16: 0 to 65,535
uint32: 0 to 4.2B
uint64: 0 to 18 quintillion
Zero Value: 0
Example:
go
var count uint32 = 100000
rune
Alias for: int32
Use Case: Unicode code points (e.g., ‘☺’, ‘あ’).
Example:
go
var emoji rune = ‘🔥’ // Unicode U+1F525
Floating-Point
float32: 6-7 decimal digits precision
float64: 15-16 digits (preferred)
Zero Value: 0.0
Example:
go
var pi float64 = 3.1415926535
Complex Numbers
complex64: float32 real/imaginary parts
complex128: float64 real/imaginary parts
Zero Value: (0+0i)
Example:
go
var z complex128 = 3 + 4i
uintptr
Purpose: Holds memory addresses (unsafe, low-level programming).
Example:
go
var ptr uintptr = uintptr(unsafe.Pointer(&x))