user440096
user440096

Reputation:

Difference between int var. var and &var

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 they would be the same.

Upvotes: 0

Views: 166

Answers (2)

Jasarien
Jasarien

Reputation: 58448

&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.

Upvotes: 2

Itay Karo
Itay Karo

Reputation: 18296

&gameUniqueID is the address of the variable gameUniqueID.

Upvotes: 1

Related Questions