首页 > 试题广场 >

NSMutableString * s =&...

[单选题]
NSMutableString * s = [[NSMutableString alloc] initWithFormat:@"hello"];
NSLog(@"s = %p",s);
[s appendFormat:@"world"];
NSLog(@"s = %p",s);
上述代码两次打印地址的值是否相同(      ) 
  • 相同
  • 不同
  • 有时相同,有时不同
  • 其他几项都不对
NSMutableString字符串内容是可变的,append只是更改内容,而指向对象的头地址是不变的。
发表于 2022-11-29 17:48:16 回复(0)

%p在c语言中是以十六进制整数方式输出指针的值,两次指针相同
放入Xcode编译通过得到如下:
2022-02-21 15:50:31.756511+0800 DemoOC[41971:633793] s = 0x6000020f1f20


2022-02-21 15:50:31.756681+0800 DemoOC[41971:633793] s = 0x6000020f1f20 
发表于 2022-02-21 16:19:25 回复(0)