我想要NSLog指向指针的地址。我遇到了this 但是我仍然收到错误。这是我的代码
Teacher* t = [[Teacher alloc]init];
NSLog(@"t points to the address <%p>" &*t);//Error
错误是
Invalid operands to binary expression ('NSString *' and 'Teacher')
关于如何打印指针地址的任何建议?
答案 0 :(得分:7)
语法错误是由缺少逗号引起的:
NSLog(@"t points to the address <%p>", &*t);
--------^
编译器将表达式读为
(@"t points to the address <%p>") & (*t) // 'NSString *' & 'Teacher'
除此之外,您可以将&*t
简化为t
:
NSLog(@"t points to the address <%p>", t);