Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I print out the Memory Address of a variable?

Tags:

objective-c

I'd like to print what's behind an &myVariable. I tried NSLog(&myIntVar); but it won't work.

like image 921
Thanks Avatar asked Apr 29 '09 13:04

Thanks


People also ask

How do you print the memory address of a variable in Python?

It can be done in these ways:Using id() function. Using addressof() function. Using hex() function.

How do you get the memory address of a variable in C++?

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.

Which function is used to display the memory address of a variable?

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.


1 Answers

The argument to NSLog needs to be an NSString, so you want

NSLog(@"%p", &myIntVar);
like image 151
smorgan Avatar answered Oct 07 '22 00:10

smorgan