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

More Examples of Disk File I/O

More Examples of Disk File I/O

The following sections show several more examples of disk file I/O, such as reading and writing binary data and redirecting the standard streams. Three more I/O functions, fscanf(), fprintf(), and freopen(), are introduced, too.

Random Access to Disk Files

Random Access to Disk Files

Exercises : Answer the following Question

To help solidify your understanding of this 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 What are the differences between a text stream and a binary stream?

Reading and Writing Disk Files

Reading and Writing Disk Files