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

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 W orkshop 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

    In the following list, which statements are legal?
        char str1[5] = "Texas";
        char str2[] = "A character string";
        char str3[2] = "A";
        char str4[2] = "TX";
    Given a char pointer variable ptr_ch, are the following statements legal?
        *ptr_ch = `a';
        ptr_ch = "A character string";
        ptr_ch = `x';
        *ptr_ch = "This is Quiz 2.";
    Can the puts() function print out the null character in a character array?
    Which format specifier do you use with the scanf() function to read in a string, and which one do you use to read a floating-point number?

Exercises

    Given a character array in the following statement,

    char str1[] = "This is Exercise 1.";

    write a program to copy the string from str1 to another array, called str2.
    Write a program to measure the length of a string by evaluating the elements in the character array one by one. To prove you get the right result, you can use the strlen() function to measure the same string again.
    Rewrite the program in Listing 13.4. This time, convert all uppercase characters to their lowercase counterparts.
    Write a program that uses the scanf() function to read in two integers entered by the user, adds the two integers, and then prints out the sum on the screen.

Related Items

Using Unions

Using Unions

Now let's focus on the applications of unions. Basically, there are two kinds of union applications, which are introduced in the following two sections.
Referencing the Same Memory Location Differently

Unions Versus Structures

Unions Versus Structures

What Is a Union?

What Is a Union?

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

Question and Answer

    Q What are the left and right values?