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

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 does the following statement do?

    int array_int[4] = {12, 23, 9, 56};

    Given an array, int data[3], what's wrong with the following initialization?

    data[1] = 1;
    data[2] = 2;
    data[3] = 3;

    How many dimensions do the following arrays have?
        char array1[3][19];
        int array2[];
        float array3[][8][16];
        char array4[][80];
    What's wrong with the following declaration?

    char list_ch[][] = {
             `A', `a',
             `B', `b',
             `C', `c',
             `D', `d',
             `E', `e'};

Exercises

    Given this character array:

    char array_ch[5] = {`A', `B', `C', `D', `E'};

    write a program to display each element of the array on the screen.
    Rewrite the program in exercise 1, but this time use a for loop to initialize the character array with `a', `b', `c', `d', and `e', and then print out the value of each element in the array.
    Given this two-dimensional unsized array:

    char list_ch[][2] = {
             `1', `a',
             `2', `b',
             `3', `c',
             `4', `d',
             `5', `e',
             `6', `f'};

    write a program to measure the total bytes taken by the array, and then print out all elements of the array.
    Rewrite the program in Listing 12.5. This time put a string of characters, I like C!, on the screen.
    Given the following array:

    double list_data[6] = {
             1.12345,
             2.12345,
             3.12345,
             4.12345,
             5.12345};

    use the two equivalent ways taught in this lesson to measure the total memory space taken by the array, and then display the results on the screen.

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?