c++ pointers

Feb 26, 2016 at 2:29am
why my program crashes,if i do this?
int *p;
*p=2;
cout<<p<<endl;
Feb 26, 2016 at 2:42am
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.