Following are the basic data types in Go:
Numeric
// Integer Types
uint8 // Unsigned 8-bit integers (0 to 255)
uint16 // Unsigned 16-bit integers (0 to 65535)
uint32 // Unsigned 32-bit integers (0 to 4294967295)
uint64 // Unsigned 64-bit integers (0 to 18446744073709551615)
int8 // Signed 8-bit integers (-128 to 127)
int16 // Signed 16-bit integers (-32768 to 32767)
int32 // Signed 32-bit integers (-2147483648 to 2147483647)
int64 // Signed 64-bit integers (-9223372036854775808 to 9223372036854775807)
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// Floating Types
float32 // IEEE-754 32-bit floating-point numbers
float64 // IEEE-754 64-bit floating-point numbers
complex64 // Complex numbers with float32 real and imaginary parts
complex128 // Complex numbers with float64 real and imaginary parts
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// Other Numeric Types
byte // same as uint8
rune // same as int32
uint // 32 or 64 bits
int // same size as uint
uintptr // an unsigned integer to store the uninterpreted bits of a pointer value
Handling Overflows
- At
compile time, a Gocompilercan catchoverflow errors. - In runtime, when
overflowsoccurs:integerwrap arounds and go to their minimum and maximum values.floatwrap arounds topositive infinityornegative infinity.
Boolean
bool // Represents 'true' or 'false'
String
- In Go language, strings are different from other languages like Java, C++, Python, etc.
- Strings can’t be
nullin Go. - It is a sequence of variable-width characters where each and every character is represented by one or more bytes using UTF-8 Encoding.
- In Go, a
stringis in effect is a read-only slice of bytes (immutable). - Or in other words, strings are the immutable chain of arbitrary bytes (including bytes with zero value) and the bytes of the strings can be represented in the Unicode text using UTF-8 encoding.
- String literals can be created in 2 ways:
- Using double quotes
- Using backticks
https://github.com/aditya43/golang#strings-runes-and-bytes