Now it's time to see more details. For example, a "int" variable can store numbers up to about nine digits, both positive and negative, and occupies 4 bytes in memory.
(Note: If you do not know what a byte is, you should look at Appendix 1 of this text).
But it is not the only option. For instance, if we want a variable for a person's age, there is no need to use negative numbers, and 3 digits would be enough, so we can expect to find a more appropriate data type, which wastes less memory. There is also the opposite case: a bank may need to handle numbers with more than 9 digits, so an "int" would not be a good choice. In fact, if we talk about currency values, we would also need to use decimals, but we'll leave that for the next section.
No comments:
Post a Comment