Understanding types is super critical to being able to program. Without this knowledge it would be like trying to go through life where everything you see and feel is unknown to you.
If somebody points to a random spot in a computer’s memory and asks “What’s that? Do we need it anymore?” You can’t just pick it up and look at it. It’s just some binary bits. Some values. You don’t even know how many there are or if you’re looking at the beginning, middle, or end. You might even be looking at a spot in memory that has nothing. You can’t tell because even nothing has no meaning.
What are these types that are available to you? It depends on the language. Here are 11 common types with a short description for each.
- Integer types represent whole numbers including zero. There will usually be several sizes of this basic type available that will fit in 8, 16, 32, or 64 bytes. Some common names are short, int, and long and the specific sizes are not always fully specified by a language. There are also signed and unsigned versions of the integer types that determine if negative values are allowed.
- Boolean types allow you to keep track of true and false values.
- Floating point types give you the ability to approximate decimal numbers including fractional values.
- Character types are very similar to the integer types because they only need whole numbers. The major difference is that these types use codes that map to character values. The codes are standardized and agreed on although there are multiple standards and it’s not always obvious which standard is being used.
- Void is a special type that means there is no type.
- String types are really just a collection of characters but there are enough special rules especially with various cultures and regions that will make you glad to have strings as their own type.
- Pointer types need another type to be complete. This other type could even be another pointer.
- Reference types act a lot like pointers but don’t look like them.
- Array types also need another type to be complete and define a collection of the other type.
- Custom types can be anything you want and are defined by including other built-in and custom types.
- Enumeration types are custom types that allow you to give meaningful names to values.