Sams Teach Yourself C in 21 Days

(singke) #1
Pointers: Beyond the Basics 437

15


Exercises ........................................................................................................


  1. Write a declaration for a pointer to a function that takes an integer as an argument
    and returns a type floatvariable.

  2. Write a declaration for an array of pointers to functions. The functions should all
    take a character string as a parameter and return an integer. What could such an
    array be used for?

  3. Write a statement to declare an array of 10 pointers to type char.
    4.BUG BUSTER:Is anything wrong with the following code?
    int x[3][12];
    int *ptr[12];
    ptr = x;

  4. Write a structure that is to be used in a single-linked list. This structure should hold
    your friends’ names and addresses.
    Because of the many possible solutions, answers are not provided for the following exer-
    cises.
    6.ON YOUR OWN:Write a program that declares a 12[ts]12 array of characters.
    Place X’s in every other element. Use a pointer to the array to print the values to
    the screen in a grid format.
    7.ON YOUR OWN:Write a program that uses pointers to type doublevariables to
    accept 10 numbers from the user, sort them, and print them to the screen. (Hint:
    See Listing 15.10.)
    8.ON YOUR OWN:Modify the program in exercise 7 to allow the user to specify
    whether the sort order is ascending or descending.


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

Free download pdf