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 Null Statement

The Null Statement

Looping Under the for Statement

Looping Under the for Statement

The general form of the for statement is

for (expression1; expression2; expression3) {
   statement1;
   statement2;
   .
   .
   .
}

Using Nested Loops

Using Nested Loops

You can put a loop inside another one to make nested loops. The computer will run the inner loop first before it resumes the looping for the outer loop.

Listing 7.7 is an example of how nested loops work.

 

The do-while Loop

The do-while Loop

You may note that in the for and while statements, the expressions are set at the top of the loop. However, in this section, you're going to see another statement used for looping,

The while Loop

The while Loop

The while statement is also used for looping. Unlike the situation with the for statement, there is only one expression field in the while statement.

The general form of the while statement is

while (expression) {