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

Manipulating Bits

Manipulating Bits

In previous hours, you learned that computer data and files are made of bits (or bytes). There is even an operator in C_the sizeof operator_that can be used to measure the number of bytes for data types.

Everything Is Logical

Everything Is Logical

Now, it's time for you to learn about a new set of operators: logical operators.

There are three logical operators in the C language:
&&     The logical AND operator
||     The logical OR operator

Question and Answer

    Q Why do we need the sizeof operator?

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.

Playing with an Infinite Loop

Playing with an Infinite Loop

If you have a for statement like this,

for ( ; ; ){
  /* statement block */
}