Exercises : Answer the following Question

Submitted by tushar pramanick on Fri, 03/08/2013 - 00:42

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."

    How can you obtain the left value of a character variable ch?
    In the following expressions, does the asterisk (*) act as a dereference operator or as a multiplication operator?
        *ptr
        x * y
        y *= x + 5
        *y *= *x + 5
    Given that x = 10, the address of x is 0x1A38, and ptr_int = &x, what will ptr_int and *ptr_int return, respectively?
    Given that x = 123, and ptr_int = &x after the execution of *ptr_int = 456, what does x contain?

Exercises

    Given three integer variables, x = 512, y = 1024, and z = 2048, write a program to print out their left values as well as their right values.
    Write a program to update the value of the double variable flt_num from 123.45 to 543.21 by using a double pointer.
    Given a character variable ch and ch = `A', write a program to update the value of ch to decimal 66 by using a pointer.
    Given that x=5 and y=6, write a program to calculate the multiplication of the two integers and print out the result, which is saved in x, all in the way of indirection (that is, using pointers).

Related Items

The Basics of Disk File I/O

The Basics of Disk File I/O

Now let's focus on how to open and close a disk data file and how to interpret error messages returned by I/O functions.

Files Versus Streams

Files Versus Streams

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 What are the differences between a union and a structure?

Making Structures Flexible

Making Structures Flexible

The second application of unions is to nest a union inside a structure so that the structure can hold different types of values.