c++ pointers

why my program crashes,if i do this?
int *p;
*p=2;
cout<<p<<endl;
A pointer needs to point to something.
p is not initialised, it contains garbage.
That's ok until you try to modify the value pointed to, it is changing some random memory not owned by your program.
Topic archived. No new replies allowed.