-3

I want to know what will be the result of the following code

NSString *str = @"0";
NSString *str1 = @"12";
NSLog(@"str int value %d, %d",str, str1);

Result I got is 18036, 18052

I used a wrong format specifier in my code and came across this weird result. I fixed it later through. But I wanted to know what exactly it print out.

Thanks

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
pa12
  • 1,493
  • 4
  • 19
  • 40

2 Answers2

1

NSLog(@"str int value %d, %d",str, str1);

You're passing pointers to strings as the parameters, but the format string specifies integers. A good guess is that the pointers will be interpreted as integers, so the output will depend on where in memory the strings happen to be allocated.

Caleb
  • 124,013
  • 19
  • 183
  • 272
0

I guess it printed out the string pointer address

Nikita Ilyasov
  • 500
  • 2
  • 14
  • 1
    This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient [reputation](http://stackoverflow.com/faq#reputation) you will be able to [comment on any post](http://stackoverflow.com/privileges/comment). – nickhar Mar 28 '13 at 20:34
  • I though so, but I wanted to know for sure what it is displaying. – pa12 Mar 28 '13 at 20:48
  • The question was "But I wanted to know what exactly it print out." I suppose my answer was pretty close – Nikita Ilyasov Mar 28 '13 at 20:54