Sams Teach Yourself C in 21 Days

(singke) #1
Pointers: Beyond the Basics 435

15


Q Is there a difference between a pointer to a string and a pointer to an array of
characters?
ANo. A string can be considered an array of characters.
Q Is it necessary to use the concepts presented in today’s lesson to take advan-
tage of C?
AYou can use C without ever using any advanced pointer concepts; however, you
won’t take advantage of the power that C offers. Pointer manipulations such as
those shown in today’s lesson can make many programming tasks easier and more
efficient.
Q Are there other times when function pointers are useful?
AYes. Pointers to functions also are used with menus. Based on a value returned
from a menu, a pointer is set to the function that should be called based on the
menu choice.
Q Name two major advantages of linked lists.
AOne: The size of a linked list can be increased or decreased while the program is
running; it doesn’t have to be predefined when you write the code. Two: It’s easy
to keep a linked list in sorted order, because elements can easily be added or
deleted anywhere in the list.

Workshop ............................................................................................................


The Workshop provides quiz questions to help you solidify your understanding of the
material covered and exercises to provide you with experience in using what you’ve
learned.

Quiz ..............................................................................................................


  1. Write code that declares a type floatvariable, declares and initializes a pointer to
    the variable, and declares and initializes a pointer to the pointer.

  2. Continuing with the example in question 1, say that you want to use the pointer to
    a pointer to assign the value 100 to the variable x. What, if anything, is wrong with
    the following assignment statement?
    *ppx = 100;
    If it isn’t correct, how should it be written?

  3. Assume that you have declared an array as follows:
    int array[2][3][4];
    What is the structure of this array, as seen by the C compiler?


25 448201x-CH15 8/13/02 11:13 AM Page 435

Free download pdf