一、概念
二、代码
#import <Foundation/Foundation.h>
#pragma mark 类
#pragma mark main函数
@interface Person : NSObject
{
@public
int age;
double height;
}
- (void)printf;
@end
void text1(int newAge, double newHeight);
void text2(Person *newP);
void text3(Person *newP);
void text4(Person *newP);
int main()
{
Person *p = [Person new];
p->age = 10;
p->height = 1.5f;
text1(p->age, p->height); // 10 1.5f
[p printf]; // 10 1.5f
text2(p); // 指针,地址
[p printf]; // 20, 1.71
#warning 主要text3复杂一点 因为内部 开辟了一块新的存储空间 需要看清楚指向谁
text3(p); // 指针,地址
[p printf]; // 20 1.71
text4(p); // 指针,地址
[p printf]; // 33, 1.99
}
@implementation Person
- (void)printf
{
NSLog(@"年龄 = %i,身高 = %f",age,height);
}
@end
void text1(int newAge, double newHeight)
{
newAge = 30;
newHeight = 1.6f;
}
// Person *newP = p
void text2(Person *newP)
{
newP->age = 20;
newP->height = 1.71f;
}
void text3(Person *newP)
{
Person *p2 = [Person new];
p2-> age = 40;
p2-> height = 1.8f;
newP = p2;
newP->age = 30;
}
void text4(Person *newP)
{
Person *p2 = newP;
p2 -> age = 50;
p2 -> height = 1.99f;
newP -> age = 33;
}
log
年龄 = 10,身高 = 1.500000
年龄 = 20,身高 = 1.710000
年龄 = 20,身高 = 1.710000
年龄 = 33,身高 = 1.990000