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 #define and #undef Directives

The #define and #undef Directives

The #define directive is the most common preprocessor directive, which tells the preprocessor to replace every occurrence of a particular character string (that is, a macro name) with a specified value (that is, a macro body).

The C Preprocessor Versus the Compiler

The C Preprocessor Versus the Compiler

One important thing you need to remember is that the C preprocessor is not part of the C compiler.

What Is the C Preprocessor?

If there is a constant appearing in several places in your program, it's a good idea to associate a symbolic name to the constant, and then use the symbolic name to replace the constant throughout the program. There are two advantages to doing so. First, your program will be more readable.

Exercises : Answer the following Question

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.

Question and Answer

    Q Why is random access to a disk file necessary?