How this is working?

Hello to everyone ,i found the following code somewhere and i can understant how this is working?

int a=312312;
int* b;
b=(int *)a;

cout<<"b-->"<<b<<endl;
//cout<<"*b-->"<<*b<<endl; //This is not working,why?
return 0;

Firstly I cant understant how you can pass a value to pointer without reference.I mean the logical it would be b=&a and not b=(int *)a; Also when i try to print the value of pointer my system crash althougth the compiler doesn't not return any value.Can someone explain me what is going on?
Hello kikirikou,

you already found out that it doesn't work. if 312312 ('a's content which is actually converted to a pointer) would be a valid address to something it would work otherwise it crashes
b=(int *)a; is a C style casting,it is considered obsolete in C++.You are trying to dereference b but its pointing nowhere.Use the & operator instead.Cheers.
Ok got it,thanks!!!
Topic archived. No new replies allowed.