3 Primitive types and operators
This chapter covers
- Numeric types and numeric operations
- The
booltype - Structs
- Pointers
- Strings, runes, and string manipulation
Go comes with a number of types built into the language for some of the most common computing tasks, such as working with numbers, strings, and Boolean types. In a statically typed language like Go, these built-in types are often called primitive types because they are the building blocks for all the other types in the language.
Primitive types are the most fundamental tools in your toolbelt when building software with Go, and you will use them in every program you write. If you think of writing software as building a house, the types in this chapter are like the nails and screws that hold everything together.
In this chapter, you’ll learn more about these fundamental types, along with some tips for using them most effectively.
3.1 Integer types
Integer types store whole numbers within a certain range, depending on their size. In Go, we have two varieties of integer—signed and unsigned, which are outlined in table 3.1—and there are several different size variations for each, as well as a couple of alias types that declare alternate names for certain circumstances. Integer types are very common in Go and are used for basic math, array and slice indices, and configuration arguments for many of the standard library functions.