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

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.