本帖最后由 程序猿-2014 于 2014-4-11 14:34 编辑
#import <Foundation/Foundation.h>
@interface Person : NSObject
{
@public
int age;
double height;
}
- (void)print;
@end
void test(Person *newP);
void test1(Person *newP);
int main(int argc, const char * argv[])
{
Person *p = [Person new];
p->age = 10;
p->height = 1.5f;
test(p);
[p print];
test1(p);
[p print];
return 0;
}
@implementation Person
- (void)print
{
NSLog(@"年龄=%d,身高=%f", age, height);
}
@end
void test(Person *newP)
{
Person *p2 = [Person new];
p2->age = 40;
p2->height = 1.8;
newP = p2;
newP->age = 30;
}
void test1(Person *newP)
{
Person *p2 = newP;
p2->age = 50;
p2->height = 1.9;
newP->age = 60;
}
谁能告诉我这道题 在内存中是怎么运行的呢? 最好能附带张图 谢谢! |