Contents    Prev    Next    Page+10   

What is the motivation for the union construct in C? (Multiple data, possibly different types, share the same storage location.)

  • A: prevents errors
  • B: improves the literary style of code
  • C: saves space
  • D: runs faster
  • E: automatic type conversion

    Answer:   C

    A is wrong: the union is an open invitation to commit undetected type errors.

    B is wrong: there is no change in the style of code.

    C is correct: if only one of the values can be used at any given time, space is saved by putting all the alternatives in the same place. This is only worth doing, however, if a large number of such records will be created.

    D is wrong because there is no change in execution time.

    E is wrong because there is no automatic type conversion.