
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