Some answers to questions on simple, scalar types

  1. Why is it unsafe to store a long value in an int variable, yet the converse is quite safe?
    The definition guarantees that an int must no bigger then a double and hold values no greater than those that a double can hold. On the other hand, a double must be as big as an int, but can be and often is bigger. If you store a value from a double into an int location it will be truncated to fit if necessary.

    An int is typically held in 4 bytes while a double is typiccally held in 8 bytes.

  2. Evaluate the following as True or False.
    1. 3 - 6
      True (negative value)
    2. 6 - 3
      True (positive value)
    3. 4 - 4
      False (zero)
Answers to the questions.
Back to the note on types