To determine how much space is wasted, if at all, you need to consider the range of values that you want to store in your int
variable, not just the current value.
If your int
is 32-bit in size, and you want to store positive and negative values in it in the range between -2,000,000,000 and 2,000,000,000, then you need all 32 bits, so none of the bits in your int
are wasted. If, on the other hand, the range is from -30,000 to 30,000, then you could have used a 16-bit data type, so two bytes are wasted.
Note that sometimes "wasting" a few bytes comes with an improvement in speed, because a larger size happens to be the "native" size for the CPU's registers. In this case a "waste" becomes a "trade-off", because you get extra speed for using additional memory space.