Study Guide 5: Structures

  1. A structure brings together a collection of
    1. variables of the same data type.
    2. variables of any data type.
    3. integers with user-defined names.
    4. named constants of any type.
  2. The closing brace of a structure is followed by a ___________
  3. A structure specification creates or allocates space in memory for a variable.
    1. True
    2. False
  4. A structure variable definition creates or allocates space in memory for a variable.
    1. True
    2. False
  5. When using the dot operator with a structure, the identifier to the left of the dot operator is the name of
    1. a structure member or field.
    2. a structure tag.
    3. a structure variable or object.
    4. the keyword struct.
  6. When using the dot operator with a structure, the identifier to the right of the dot operator is the name of
    1. a structure member or field.
    2. a structure tag.
    3. a structure variable or object.
    4. the keyword struct.
  7. When using the arrow operator with a structure, the identifier to the left of the arrow operator is the name of
    1. a structure member.
    2. a structure tag.
    3. a pointer to a structure variable or object.
    4. the keyword struct.
  8. When using the arrow operator with a structure, the identifier to the right of the arrow operator is the name of
    1. a structure member.
    2. a structure tag.
    3. a pointer to a structure variable or object.
    4. the keyword struct.
  9. Examine the following structure specification and variable definition below:
    struct foobar
    {
    	int	foo;
    	char	bar;
    };
    . . . .
    foobar fb;
    Which of the following correctly accesses a field in the structure?
    1. fb.foo
    2. fb->foo
    3. The correct field access is not shown.
  10. Examine the following structure specification and variable definition below:
    struct foobar
    {
    	int	foo;
    	char	bar;
    };
    . . . .
    foobar* fb;
    // fb is initialized
    Which of the following correctly accesses a field in the structure?
    1. fb.bar
    2. fb->bar
    3. The correct field access is not shown.
  11. Write a structure specification for a structure named Time (remember that C++ is case sensitive) that includes three fields of type int - called hours, minutes, and seconds.
  12. Write a statement that defines an automatic variable named time2 and whose type is a Time structure.
  13. Write a statement that sets the hours member of the automatic time2 structure variable equal to 11 without changing the values stored in minutes and seconds.
  14. You can assign one structure variable to another, provided they are of the same structure type.
    1. True
    2. False
  15. Modern enumerations can contain objects, but the older, basic or traditional enumerations are collections of
    1. variables of different data types.
    2. related data variables.
    3. integers with user-defined names.
    4. floating point numbers with user-defined names.
  16. Unless a programmer explicitly sets different values, the first three enumerators or elements of an enum normally represent the values __________, _________, and _________
  17. Based on the following enumeration, what is the value of ERROR?
    enum { READ, WRITE, EXECUTE, ERROR };
    1. 0
    2. 1
    3. 2
    4. 3
    5. 4
    6. 5
    7. The statement will not compile because a value is not assigned to any names.
  18. Based on the following enumeration, what is the value of ERROR?
    enum { READ = 2, WRITE = 4, EXECUTE = 8, ERROR = 16 };
    1. 9
    2. 10
    3. 11
    4. 16
    5. 32
    6. The statement will not compile because values cannot be assigned to enumerators.
    7. The statement will not compile because it is missing the enumeration tag.
  19. Based on the following enumeration, what is the value of ERROR?
    enum { READ = 2, WRITE = 4, EXECUTE = 8, ERROR };
    1. 9
    2. 10
    3. 11
    4. 16
    5. 32
    6. The statement will not compile because ERROR is not assigned a value
    7. The statement will not compile because it is missing the enumeration tag.
  20. Which of the following is NOT a benefit of symbolic constants?
    1. Naming constants can provide shorthand names for long values.
    2. Naming constants can help the program run more efficiently.
    3. Names can help clarify the meaning or purpose of a value in the program.
    4. Naming constants can make maintaining or modifying a program easier.
  21. A program specifies a structure named Foo and defines two automatic Foo variables named x and y. Write the statements needed to swap the values stored in x and y.