Some questions on unions in C

  1. Why is the following type dangerous? Why might it be useful?
    union mixer{
       unsigned u_val;
       float f_val;
    };
    
  2. struct car_part {
          char * name;
          char * maker:
          union {
             int capacity;
             char * style:
             struct radio rpt;
          }
    };
    
    struct car_part cp;
    
    Write an assignment to the name, capacity and radio's min_freq fields in cp.

Answers to these questions.


Back to notes on unions.