目标 C语言 如何在 NSLog 中打印 int * 和 unsigned int*?



如何使用NSLog在日志中打印int* (int指针)和unsigned int* ?

- (int) doSomethingWith:(unsigned int)Msg withWparam:(unsigned int*)wParam withParameter:(int *) lParam
{
    NSLog(@"MSg:%d wParam:%u lParam:%u",Msg,wParam,lParam);
//not working
    return 1;
}

警告: Format specifies type 'unsigned int' but the argument has type 'unsigned int *'

%d代替int。形参是指针,所以使用*来访问所指向的值。

NSLog(@"MSg:%d wParam:%u lParam:%d",Msg,*wParam,*lParam);

%@用于对象。BOOL不是对象。你应该使用%d
基于数据类型,%@更改如下

For Strings you use %@
For int  you use %i
For float you use %f
For double you use %lf

最新更新