I'd like to print what's behind an &myVariable. I tried NSLog(&myIntVar); but it won't work.
It can be done in these ways:Using id() function. Using addressof() function. Using hex() function.
In c++ you can get the memory address of a variable by using the & operator, like: cout << &i << endl; The output of that cout is the memory address of the first byte of the variable i we just created.
In C, we can get the memory address of any variable or member field (of struct). To do so, we use the address of (&) operator, the %p specifier to print it and a casting of (void*) on the address.
The argument to NSLog needs to be an NSString, so you want
NSLog(@"%p", &myIntVar);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With