First write a person class Person.h
1 #import<Foundation/Foundation.h>2 3 @interfacePerson:nsobject4 {5 @public6 intAge ;7 Doubleheight;8 }9- (void) print;Ten One @end
Person.m
1 #import " person.h " 2 @ Implementation person 4 -(void 5 { @" age =%d, height =%f " 7 8 @end
Main.m
1 #import<Foundation/Foundation.h>2 #import "Person.h"3 voidTest1 (intNewAge,Doublenewheight);4 voidTest2 (Person *NEWP);5 voidTEST3 (Person *NEWP);6 voidTEST4 (Person *NEWP);7 8 intMainintargcConst Char*argv[]) {9 @autoreleasepool {TenPerson *p = [personNew]; OneP->age =Ten; AP->height =1.5f; - -Test1 (P->age, p->height); the[P print];//Ten 1.5 - -Test2 (P);//1.7 - [P print]; +NSLog (@"before = aft%@", p); -Test3 (P);//1.7 + [P print]; ANSLog (@"After =%@", p); at -Test4 (P);//1.9 - [P print]; - - } - return 0; in } - to voidTest1 (intNewAge,Doublenewheight) + { -NewAge =Ten; theNewheight =1.6; * } $ Panax Notoginseng voidTest2 (Person *NEWP) - { theNewp->age = -; +Newp->height =1.7; A } the + voidTEST3 (Person *NEWP) - { $NSLog (@"just passed in parameter address NEWP =%@", NEWP); $Person *P2 = [personNew];//P2 point to a new storage space -P2->age = +; -P2->height =1.8; theNEWP = p2;//point the new storage space of P2 to newp here the change just changes the contents of the P2 without making changes to the address NEWP originally pointed to -NSLog (@"NEWP Changed address =%@", NEWP);WuyiNewp->age = -; the } - Wu voidTEST4 (Person *NEWP) - { AboutPerson *p2 = NEWP;//Assigning a NEWP address to P2 and then making changes to the P2 content is actually equivalent to changing the contents of the NEWP $P2->age = -; -P2->height =1.9; -Newp->age = -; -}
Operation Result:
2015-06-30 11:11:43.933 test[40776:1124334] Age =10, height =1.500000
2015-06-30 11:11:43.934 test[40776:1124334] Age =20, height =1.700000
2015-06-30 11:11:43.934 test[40776:1124334] before = aft<person:0x100211ba0>
2015-06-30 11:11:43.935 test[40776:1124334] just passed in parameter address NEWP = <Person:0x100211ba0>
2015-06-30 11:11:43.935 test[40776:1124334] NEWP changed address = <Person:0x100100330>
2015-06-30 11:11:43.935 test[40776:1124334] Age =20, height =1.700000
2015-06-30 11:11:43.935 test[40776:1124334] after = <Person:0x100211ba0>
2015-06-30 11:11:43.935 test[40776:1124334] Age =60, height =1.900000
Use the example to tell you the OC pointer parameter