我想NSLog指向指针的地址.我遇到了这个 但是我仍然遇到错误.这是我的代码
Teacher* t = [[Teacher alloc]init];
NSLog(@"t points to the address <%p>" &*t);//Error
Run Code Online (Sandbox Code Playgroud)
错误是
Invalid operands to binary expression ('NSString *' and 'Teacher')
Run Code Online (Sandbox Code Playgroud)
关于如何打印指针地址的任何建议?
语法错误是由缺少逗号引起的:
NSLog(@"t points to the address <%p>", &*t);
--------^
Run Code Online (Sandbox Code Playgroud)
编译器将您的表达式读为
(@"t points to the address <%p>") & (*t) // 'NSString *' & 'Teacher'
Run Code Online (Sandbox Code Playgroud)
除此之外,您可以简化&*t为t:
NSLog(@"t points to the address <%p>", t);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
138 次 |
| 最近记录: |