enum, typedef

  1. Which of the following enumerated type declarations are legal? Circle all that work.
    1. enum Grade {A, B, C, D, F};
    2. enum Grade {A, A-, B+, B, B-, C+, C, C-, D, F};
    3. enum Season {winter, spring, summer, fall};
    4. enum cutoff {50, 60, 70, 80, 90};
    5. enum flavors {vanilla, chocolate, strawberry, coffee, peach};
    6. enum flavors {Cookie Dough, Mint Chocolate Chip};
    7. enum flavors {chocolate};
  2. Write an enumerated type called boolean with true and false values.
  3. What is the output of the following program?
    #include <stdio.h>
    enum Seasons {winter, spring, summer, fall};
    void changeSeason( enum Seasons ssn );
    int main( ) {
       enum Seasons season;
       season = fall;	
       printf( "The season before function is %d\n", season );
       changeSeason( season );
       printf( "The season after function is %d\n", season );
    }
    void changeSeason( enum Seasons ssn ) {
    	ssn = summer;	
    }
    
  4. The enumerated type (enum) is derived from what data type? (char, boolean, float, int, struct)
  5. True/False: Fields in an enumerated type can have different data types.
  6. How does a typedef struct differ from a regular struct?
  7. True/False: You can declare a typedef with variables as follows:
    typdef struct
    {
       int x;
       int y;
    } Coords ptA, ptB;
    
  8. Which of the following correctly make use of typedef? Circle all that work.
    1. typedef int integer;
    2. typedef double vector[50];
    3. typedef double matrix[50][100];
    4. typedef struct { char name[20]; int id; } empRec;
    5. TYPEDEF Double vector[50];
    6. typedef double[ ];
  9. Given a typedef structure definition, how do you access the elements in it?
  10. Can a union type be nested inside a typedef struct definition?
  11. Can a enum type be nested inside a struct definition?