Reputation: 87
string *p1 = new string(“hello”);
string *p2 = new string(“world”);
string *p3 = new string(“!!!”);
cout << p1 << ‘ ‘ << p2 << ‘ ‘ << p3 << endl; // print: 0xffa0 0xffb1 0xffd5
string *m[3] = {p1, p2, p3}; // Σημείωση: 32bit αρχιτεκτονική
cout << m; // print: 0x1000
cout << _____m[_____]; // print: 0xffb1 (1 μονάδα)
cout << &m[1]; // print: ___________________ (1 μονάδα)
cout << _____m[_____]; // print: !!! (1 μονάδα)
cout << _____m; // print: hello (1 μονάδα)
cout << &*m[1]; // print: __________________ (1 μονάδα
I cant figure out what is happening my outputs are all references not values! its an old final exercise i must fill each gap to obtain the value that he is telling me.
Upvotes: 0
Views: 64
Reputation: 2777
cout << p1 << ‘ ‘ << p2 << ‘ ‘ << p3 << endl; just typing cout<< p1 will always lead to reference, to get value use dereference operator * like cout<<*p1
Upvotes: 0
Reputation: 36354
cout << p1 << ‘ ‘ << p2 << ‘ ‘ << p3 << endl
You print out pointers, which are (in essence) addresses of the variables they point to.
cout << *p1 << ‘ ‘ << *p2 << ‘ ‘ << *p3 << endl
would probably do the trick.
Recommended quick literature: This
Upvotes: 2