Stuck on a problem

What does ptr_thing; display?



#include <iostream>

using namespace std;


void main(void)

{

int thing = 20;

int *ptr_thing;

ptr_thing = &thing;



system("pause");

}
It doesn't "display" anything, there is no display code there.

the value of ptr_thing is the same as the value of thing.
closed account (Lv0f92yv)
Indeed, it will not display with the code above.

If you deference ptr_thing: *ptr_thing, it points to '20'.

1
2
cout << ptr_thing; //displays the address of the variable 'thing'
cout << *ptr_thing; //displays the contents at the address of the variable 'thing', 20 in this case. 


Edit: If this is just something your doing in your spare time, system("pause") is OK, but don't make it a habbit unless you have a reason to. If you're using it to keep the console open, consider alternatives, like a couple calls to getchar();.
Last edited on
Topic archived. No new replies allowed.