Exercises : Answer the following Question

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

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."
Quiz

    What are the values represented by the following enum names?

    enum months { Jan, Feb, Mar, Apr,
                  May, Jun, Jul, Aug,
                  Sep, Oct, Nov, Dec };

    What are the values represented by the following enum names?

    enum tag { name1,
               name2 = 10,
               name3,
               name4 };

    Which statements in the following are equivalent in the variable declaration?
        typedef long int BYTE32; BYTE32 x, y, z;
        typedef char *STRING[16]; STRING str1, str2, str3;
        long int x, y, z;
        char *str1[16], *str2[16], *str3[16];
    Can you pass some command-line arguments to a main() function that has the following definition?

    int main(void)
    {
       . . .
    }

Exercises

    Write a program to print out the values represented by the enumerated names declared in Quiz question 2.
    Given the following declarations:

    typedef char WORD;
    typedef int SHORT;
    typedef long LONG;
    typedef float FLOAT;
    typedef double DFLOAT;

    write a program to measure the sizes of the synonyms to the data types.

    Rewrite the program in Listing 18.4. This time, add integers starting at the value of MIN_NUM instead of the value of MAX_NUM.
    Write a program that accepts command-line arguments. If the number of command-line arguments, not including the name of the executable itself, is less than two, print out the usage format of the program and ask the user to reenter the command-line arguments. Otherwise, display all command-line arguments entered by the user.

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?