K&R2: Chaptger 5: Pointers and Arrays 
Author Message
 K&R2: Chaptger 5: Pointers and Arrays

K&R2 p.93 says:
  "A pointer is a variable that contains the address of a variable."

Is it true?  I think:
  "A pointer is a type that can hold the address of an object or a
   function, or can refer to an incomplete type."

K&R2 says:
  "Pointers are much used in C, partly because they are sometimes the
   only way to express a computation, and partly because they usually
   lead to more compact and efficient code than can be obtained in
   other ways."

What does "to express a computation" mean?
I came to a conclusion that "to return a set of results of a function."
Is it OK?

    void func(int a, int b, int *sum, int *diff)
        *sum = a + b;
        *diff = a - b;

In traditional C, a structure type value cannot be returned.
So pointers are the only way to return a set of results of a function.
But ANSI C allows a function to return a structure type.

T. Sakamoto

Sat, 30 Jan 1999 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Have K&R2, looking for simpler resource on pointers

2. K&R1 vs. K&R2

3. qsorting & managing struct arrays, pointer arrays

4. Array of pointers, pointer to array...

5. Dereferencing f-pointers, arrays of f-pointers, pointers to f-pointers

6. array pointer/pointer array

7. arrays pointers array of pointers

8. Newbie getting runtime Exception (STATUS_ACCESS_VIOLATION) trying to implement Ex. 2-4 from K&R2

9. K&R2's implicit declaration of exit()

10. New K&R2 exercise: fix getint

11. In the reference manual of K&R2 (2)

12. k&r2 question 4.3


Powered by phpBB® Forum Software