OC 언어 day02-04 연습2

1399 단어

pragma mark 연습2


pragmamark 개념


pragmamark 코드

#import 
#pragma mark  

#pragma mark main  

@interface Person : NSObject
{
    @public
    int age;
    double height;
}
- (void)print;
@end

// int newAge = 10 , double newHeight = 1.5f
void test1(int newAge, double newHeight);
void test2(Person *newP);
void test3(Person *newP);
void test4(Person *newP);

int main(int argc, const char * argv[])
{
    
    Person *p = [Person new];
    p-> age = 10;
    p-> height = 1.5f;
    
    test1(p->age, p->height);
    [p print];  // 10.1.5
    
    
    test2(p);   //      
    [p print];  // 20 1.7
    
    test3(p);   //      
    [p print];
    
    test4(p);   //      
    [p print];

    
    return 0;
}

@implementation Person

-(void)print
{
    NSLog(@"  =%d,  =%f",age,height);
}
@end

void test1(int newAge, double newHeight)
{
    newAge = 24;
    newHeight = 1.72;
}
// person *newP = p;
void test2(Person *newP)
{
    newP->age = 20;
    newP->height = 1.70;
}
void test3(Person *newP)
{
    Person *p2 = [Person new];
    p2->age = 40;
    p2->height = 1.8;
    newP = p2;  //   p2        newP                
    newP->age = 22;
}
void test4(Person *newP)
{
    Person *p2 = newP;
    p2->age = 50;
    p2->height = 1.8;
    newP->age = 60;

}


//@end

좋은 웹페이지 즐겨찾기