December 2013
Beginner
576 pages
16h 4m
English
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; ...
Read now
Unlock full access