开发者

Difference between int var. var and &var

开发者 https://www.devze.com 2023-01-16 16:47 出处:网络
HI guys, Here is some code NSString *uid = [[UIDevice currentDevice] uniqueIdentifier]; gameUniqueID = [uid hash];

HI guys,

Here is some code

 NSString *uid = [[UIDevice currentDevice] uniqueIdentifier];
 gameUniqueID = [uid hash];
 NSLog(@"gameUniqueID %d",gameUniqueID);
 NSLog(@"&gameUniqueID %d",&gameUniqueID);

The output is

gameUniqueID -1386422508
&gameUniqueID 1386832

Whats going on here? I though th开发者_如何学运维ey would be the same.


&gameUniqueID is a pointer, so you should be using %p, not %d, to output it in an NSLog.

Also, hash returns an NSUInteger (unsigned int) for which you should be using %u, not %d.


&gameUniqueID is the address of the variable gameUniqueID.

0

精彩评论

暂无评论...
验证码 换一张
取 消