Recently began my journey into C++, I've been using the book Jumping Into C++ and came across something that I didn't understand.
Quote from book:
"A good example of two variables that differ only in the amount of space they require are the double,
and its lesser twin, the float. The float was actually the original variable type that could store decimal
numbers, and the name float came from the fact that it has a decimal that can “float” into different
positions in the number. In other words, you can have two digits before the decimal and four after
(12.2345), or you can have four digits before the decimal and two after (3421.12). You aren’t limited to a
specific number of digits before and a specific number of digits after the decimal.
If you didn’t quite get that, it’s ok—the name is mostly historical. Just know that floating point numbers
mean “numbers with decimal places”. But floats have only four bytes of space, so they cannot store as
many different values as doubles, which have eight bytes of space. Back when computers had less
memory than they do today, this was a bigger deal, and programmers would often go to great lengths to
save a few bytes. Nowadays, you will almost always be better off using a double, but in cases where
space is critical (perhaps on low-memory systems like cell phones), you still have the option of using a
float."
What does he mean by a float only has 4 bytes? Doesn't a single character take up 1 byte? If someone could explain how memory works in C++, or link me to a page that can explain it, that'd be great.
Quote from book:
"A good example of two variables that differ only in the amount of space they require are the double,
and its lesser twin, the float. The float was actually the original variable type that could store decimal
numbers, and the name float came from the fact that it has a decimal that can “float” into different
positions in the number. In other words, you can have two digits before the decimal and four after
(12.2345), or you can have four digits before the decimal and two after (3421.12). You aren’t limited to a
specific number of digits before and a specific number of digits after the decimal.
If you didn’t quite get that, it’s ok—the name is mostly historical. Just know that floating point numbers
mean “numbers with decimal places”. But floats have only four bytes of space, so they cannot store as
many different values as doubles, which have eight bytes of space. Back when computers had less
memory than they do today, this was a bigger deal, and programmers would often go to great lengths to
save a few bytes. Nowadays, you will almost always be better off using a double, but in cases where
space is critical (perhaps on low-memory systems like cell phones), you still have the option of using a
float."
What does he mean by a float only has 4 bytes? Doesn't a single character take up 1 byte? If someone could explain how memory works in C++, or link me to a page that can explain it, that'd be great.











