Golang / GoLang Basics Interview Questions
What are the fundamental data types in Go?
Go has a concise but complete set of built-in primitive types. Choosing the right type — especially between int and sized integers, and between float32 and float64 — matters for correctness and interoperability.
| Category | Types | Common default |
|---|---|---|
| Signed integers | int8, int16, int32, int64, int | int (platform width: 64-bit on 64-bit OS) |
| Unsigned integers | uint8, uint16, uint32, uint64, uint | uint8 alias = byte |
| Floating point | float32, float64 | float64 (more precise; the default) |
| Boolean | bool | false |
| String | string | "" (immutable UTF-8 bytes) |
| Rune | rune (= int32) | represents a Unicode code point |
var i int = 42 var f float64 = 3.14159 var b byte = 255 // alias for uint8 var r rune = 'â¡' // alias for int32 â Unicode code point var str string = "Hello, ä¸ç" // Type conversions are ALWAYS explicit â no implicit casting var x int = 100 var y float64 = float64(x) // must be explicit var z int = int(y) // truncates decimal part // String byte count vs character count (UTF-8) fmt.Println(len(str)) // 13 bytes fmt.Println(len([]rune(str))) // 9 runes/characters // Constants are untyped by default â flexible in expressions const Pi = 3.14159 const MaxItems = 1000
More Related questions...