Basic Types
Types and Sizes
The smallest possible bit of information in a binary computer is a `0` and/or `1`. However, the smallest unit a modern computer can address is `1-byte`.
A type is what tells a compiler how to interpret the contents of memory in a meaningful way. Like, do I fetch 1,2,3,.. or 8-bytes. This may not look like it makes much of a difference for a regular C++ program, but for a CPU, and hence the compiler it makes all the difference. Fetching, and mulitplying 1-byte, vs 4 can make a huge difference for the end result.
C++ comes with the support of many types. Amongst them is `bool`, and `int`, as we have seen. An integer can also be specialized into other integer types, as we shall see. However, this requires some caution by the programmer, and some help/massaging of the compiler.
In C/C++ the `sizeof` operator can be used to output the size of a variable.
TODO - Do this, and also look at the assembly output.Integers
Integers can be signed and unsigned. In modern CPUs negative numbers are handled as 2-compliment numbers. Which means that the most siginificant bit signifies whether the number is negative or positive.
TODO - Short two's compliment description.
Unsigned integers
Unsigned integers signifies that we can only represent positive numbers (and hence a bigger range of numbers).
Fixed sized types
C++ also provides some fixed size types, such as:
std::[u]int{8,16,32,64}_t
Guaranteeing the size of the given numbers.
`std::size_t` is an integral type that is used to represent the size or length of an object.
Scientific notation
C++ also supports scientific notation, which is mainly used when consuming floating point numbers.
Types
Sticking to our integral types, which we have inspected before, an integer can have many different sizes. For portability, and for compatibility with C, and int does not have a defined size. Hence, we cannot rely on a regular `int` to be a predefined size. A `char` on the other hand, is always guaranteed to be 1-byte.
Casts
Is the way we tell the compiler that we are aware of what we are doing, and that the cast is okay, and we will not be heeding the compiler errors/warnings.