美文网首页
指针与引用的坑

指针与引用的坑

作者: 风___________ | 来源:发表于2019-12-25 15:39 被阅读0次
    + (void)load{
        [self test];
        NSLog(@"====分界线====");
        [[[ViewController alloc] init] test];
    }
    
    + (void)test{
        NSString *s = @"aaa";
        NSLog(@"%@,%p",s,s);
        [self change:&s];
        NSLog(@"%@,%p",s,s);
    }
    + (void)change:(NSString **)s{
        NSLog(@"%@,%p",*s,*s);
        *s = @"bbb";
        NSLog(@"%@,%p",*s,*s);
    }
    
    - (void)test{
        NSMutableString *s = @"aaa".mutableCopy;
        NSLog(@"%@,%p",s,s);
        [self change:s];
        NSLog(@"%@,%p",s,s);
    }
    - (void)change:(NSMutableString *)s{
        NSLog(@"%@,%p",s,s);
        [s appendString:@"bbb"];
        NSLog(@"%@,%p",s,s);
    }
    
    ViewController.m:30 aaa,0x104707548
    ViewController.m:35 aaa,0x104707548
    ViewController.m:37 bbb,0x104707588
    ViewController.m:32 bbb,0x104707588
    ViewController.m:24 ====分界线====
    ViewController.m:42 aaa,0x2834cca80
    ViewController.m:47 aaa,0x2834cca80
    ViewController.m:49 aaabbb,0x2834cca80
    ViewController.m:44 aaabbb,0x2834cca80
    

    相关文章

      网友评论

          本文标题:指针与引用的坑

          本文链接:https://www.haomeiwen.com/subject/xgmcoctx.html