Pointers and Arrays
If you have an array of 100 integers called values, you can define a pointer called valuesPtr, which you can use to access the integers contained in this array with the following statement:
int *valuesPtr;
When you define a pointer that will be used to point to the elements of an array, you don’t designate the pointer as type “pointer to array”; instead, you designate the pointer as pointing to the type of element contained in the array.
If you had an array of Fraction objects called fracts, you could similarly define a pointer to be used to point to elements in fracts with the following statement:
Fraction **fractsPtr;
To set valuesPtr to point to the first element in the values array, you just write this:
valuesPtr = values; ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access