O'Reilly logo

Programming in Objective-C, Sixth Edition by Stephen G. Kochan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required