NSLog指针指向的地址

Jam*_*nco -2 objective-c

我想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)

关于如何打印指针地址的任何建议?

Mar*_*n R 7

语法错误是由缺少逗号引起的:

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)

除此之外,您可以简化&*tt:

NSLog(@"t points to the address <%p>", t);
Run Code Online (Sandbox Code Playgroud)