c++ - Getting memory address of class member variable (non-dynamic) -


i want print memory address (i.e. 0x7ffff0...) of variable in class, gives me value of object.

i'm doing learn. don't think syntax incorrect. try 2 ways , neither works. appreciate on why doesn't work.

#include <iostream> using namespace std; class test{ public: char i; };  int main(){ test x; x.i='w'; char * y = &(x.i); cout<<"address : " <<&x.i<<endl; cout<<"address : " <<y<<endl; } 

output:

address : w address : w 

you should cast pointer void* before passing stream. you're passing char* interpreted null-terminated string.


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -