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

Using the Precision Specifier

Using the Precision Specifier

Aligning Output

Aligning Output
As you might have noticed in the previous section, all output is right-justified. In other words, by default, all output is placed on the right edge of the field, as long as the field width is longer than the width of the output.

 

Adding the Minimum Field Width

Adding the Minimum Field Width

Converting to Hex Numbers

Converting to Hex Numbers

Revisiting the printf() Function

Revisiting the printf() Function

The printf() function is the first C library function you used in this book to print out messages on the screen. printf() is a very important function in C, so it's worth it to spend more time on it.