What dereference operator?
The * in double* says that the type is a pointer. When a function returns a pointer, it indeed returns an address. The return value is an address.
What the caller does with the address is up to the caller.
What is at the address? Should be something valid, unless the address is
nullptr
.
In this case the
pmn_polynomial_value()
an address that it received from
pm_polynomial_value()
that in turn got the address from
malloc()
.
Malloc did dynamically allocate a block of memory from heap. A block large enough to store some double values in. In other words, the
pmn_polynomial_value()
's return value is the location of an array of double values.
The
pmn_polynomial_value_test()
stores the value (address) returned by
pmn_polynomial_value()
into variable
fx2_vec
. The type of
fx2_vec
is identical to the type of
pmn_polynomial_value()
; both are
double *
.
Pointers. The variable is called "pointer". The function is said to "return a pointer".
The dereferencing is then used to access a value that is stored at the address. See the second line:
1 2
|
fx2_vec = pmn_polynomial_value ( 1, n, m, x_vec );
fx2 = fx2_vec[n];
|
Can we presume that you are familiar with the kinship of brackets and the dereferencing *:
1 2 3
|
fx2_vec[ n ]
// is same as
*(fx2_vec + n)
|