knking.com -- Programming Language Books and Training

 C C++ Java

Books by K. N. King

Home
Books by K. N. King
Short courses
Recommended books
Recommended links
FAQ

C Programming: A Modern Approach (Second Edition)

Chapter 18

Answers to Selected Exercises

2. [was #2]

(a) extern
(b) static
(c) extern and static (when applied to a local variable)

4. [was #4] If f has never been called previously, the value of f(10) will be 0. If f has been called five times previously, the value of f(10) will be 50, since j is incremented once per call.

8. [was #6; modified]

(a) x is an array of ten pointers to functions. Each function takes an int argument and returns a character.
(b) x is a function that returns a pointer to an array of five integers.
(c) x is a function with no arguments that returns a pointer to a function with an int argument that returns a pointer to a float value.
(d) x is a function with two arguments. The first argument is an integer, and the second is a pointer to a function with an int argument and no return value. x returns a pointer to a function with an int argument and no return value. (Although this example may seem artificially complex, the signal function—part of the standard C library—has exactly this prototype. See p. 632 for a discussion of signal.)

10. [was #8]

(a) char *(*p)(char *);
(b) void *f(struct t *p, long int n)(void);
(c) void (*a[])(void) = {insert, search, update, print};
(d) struct t (*b[10])(int, int);

13. [was #10] (a), (c), and (d) are legal. (b) is illegal; the initializer for a variable with static storage duration must be a constant expression, and i * i doesn't qualify.

15. [was #12] (a). Variables with static storage duration are initialized to zero by default; variables with automatic storage duration have no default initial value.


Copyright © 2008, 1996 W. W. Norton & Company, Inc. All rights reserved.

Google
 
Web knking.com