Exercises : Answer the following Question

Submitted by Anonymous (not verified) on Sun, 03/10/2013 - 21:27

To help solidify your understanding of this hour's lesson, you are encouraged to answer the quiz questions and finish the exercises provided in the Workshop before you move to the next lesson. The answers and hints to the questions and exercises are given in Appendix E, "Answers to Quiz Questions and Exercises."

What's wrong with the following structure declaration?

    struct automobile {
         int year;
         char model[8];
         int engine_power;
         float weight;
         }


    How many structure variables are defined in the following statement?

    struct x {int y; char z} u, v, w;

    Given a structure declaration

    struct automobile {
         int year;
         char model[8]};

    and two car models, Taurus and Accord, which are made in 1997, initialize an array of two elements, car, that is defined with the automobile structure data type.
    In the following structure declarations, which one is a forward-referencing structure, and which one is a self-referencing structure? (Assume that the structures, employment and education, have not been declared yet.)

    struct member {
         char name[32];
         struct employment *emp;
         struct education *edu;};

    struct list {
         int x, y;
         float z;
         struct list *ptr_list;};

Exercises

    Given the following declaration and definition of a structure

    struct automobile {
         int year;
         char model[10];
         int engine_power;
         double weight;
         } sedan = {
         1997,
         "New Model",
         200,
         2345.67};

 

Related Items

The goto Statement

The goto Statement

The continue Statement

The continue Statement

The break Statement

The break Statement

You can add a break statement at the end of the statement list following every case label, if you want to exit the switch construct after the statements within a selected case are executed.

The switch Statement

The switch Statement

Nested if Statements

Nested if Statements

As you saw in the previous sections, one if statement enables a program to make one decision. In many cases, a program has to make a series of decisions. To enable it to do so, you can use nested if statements.