// archives

Pointer

This tag is associated with 4 posts

Functions Using Array Ranges

C++ functions that process arrays need to be informed about

The kind of data in the array
The location of the beginning of the array
And the number of elements in the array

The traditional C/C++ approach to functions that process arrays

Is to pass a pointer to the start of the array as one argument

And to pass the size [...]

More Array Function Examples

When you choose to use an array to represent data, you are making a design decision

But design decisions should go beyond how data is stored; they should also involve how the data is used

Often, you’ll find it profitable to write specific functions to handle specific data operations

(The profits here include increased program reliability, ease of [...]

The Implications of Using Arrays as Arguments

Let’s look at the implications of (A-1)

The function call sum_arr(cookies, ArSize)

Passes the address of the first element of the cookies array and the number of elements of the array to the sum_arr() function

The sum_arr() function

Assigns the cookies address to the pointer variable arr and assigns ArSize to the int variable n

This means (A-1) doesn’t really [...]

Creating a Reference Variable

C and C++ use the & symbol to indicate the address of a variable

C++ assigns an additional meaning to the & symbol

Presses it into service for declaring references

For example, to make rodents an alternative name for the variable rats, you could do the following (A-1):

Example of (A-1)

int rats;
int & rodents = rats; // makes rodents [...]