mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
Update c++.html.markdown
Regarding issue #1216, Better explaining the Reference 'fooRef'.
This commit is contained in:
parent
9b46fe7e57
commit
9bc553c46c
@ -245,7 +245,13 @@ cout << fooRef; // Prints "I am foo. Hi!"
|
|||||||
// Doesn't reassign "fooRef". This is the same as "foo = bar", and
|
// Doesn't reassign "fooRef". This is the same as "foo = bar", and
|
||||||
// foo == "I am bar"
|
// foo == "I am bar"
|
||||||
// after this line.
|
// after this line.
|
||||||
|
cout << &fooRef << endl; //Prints address of fooRef
|
||||||
fooRef = bar;
|
fooRef = bar;
|
||||||
|
cout << &fooRef << endl; //Prints address of fooRef, AGAIN
|
||||||
|
cout << fooRef; // Prints "I am bar"
|
||||||
|
|
||||||
|
//The address of fooRef remains the same, i.e. it is still referring to foo.
|
||||||
|
|
||||||
|
|
||||||
const string& barRef = bar; // Create a const reference to bar.
|
const string& barRef = bar; // Create a const reference to bar.
|
||||||
// Like C, const values (and pointers and references) cannot be modified.
|
// Like C, const values (and pointers and references) cannot be modified.
|
||||||
|
Loading…
Reference in New Issue
Block a user