//objects as arguments to functions--memory analysis of classes and objects//the difference between member methods and functions#import<Foundation/Foundation.h>@interfacecar:nsobject{@public intwheel; intSpeed ;}-(void) run;@end@implementationCar-(void) run{NSLog (@"%i wheels, Speed%i's car running up.", wheel,speed);}@end//function One: In this case, the value of the C->wheel is passed in and does not affect the value of the object member variablevoidTestintMints) {m= -; S= -;}//function Two: This situation can change the value of the objectvoidTest1 (car*MC) {MC->wheel=5;}//function Three: This situation will not changevoidTest2 (car*MC) {Car*C2 = [CarNew]; C2->wheel =5; C2->speed = -; MC=C2; MC->wheel =6;}intMainintargcConst Char*argv[]) {Car* C=[carNew]; C->wheel=4; C->speed= $; //test (c->wheel,c->speed);test1 (c); [C Run]; return 0;}
Object as a function parameter