Pointers, Methods, and Functions

You can pass a pointer as an argument to a method or function in the normal fashion, and you can have a function or method return a pointer as its result. When you think about it, that’s what your alloc and init methods have been doing all along—returning pointers. We cover that in more detail at the end of this chapter.

Now consider Program 13.14.

Program 13.14

// Pointers as arguments to functions#import <Foundation/Foundation.h>void exchange (int *pint1, int *pint2){   int temp;   temp = *pint1;   *pint1 = *pint2;   *pint2 = temp;}int main (int argc, char * argv[]){   @autoreleasepool {      void exchange (int *pint1, int *pint2);      int  i1 = -5, i2 = 66, *p1 = &i1, *p2 = &i2; ...

Get Programming in Objective-C, Sixth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.