From 9bc553c46ce9b7154ec7c82451d71608f4beda82 Mon Sep 17 00:00:00 2001 From: Pushkar Sharma Date: Sun, 4 Oct 2015 10:12:55 +0530 Subject: Update c++.html.markdown Regarding issue #1216, Better explaining the Reference 'fooRef'. --- c++.html.markdown | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'c++.html.markdown') diff --git a/c++.html.markdown b/c++.html.markdown index 4acc1b9d..bbd2f9a9 100644 --- a/c++.html.markdown +++ b/c++.html.markdown @@ -245,7 +245,13 @@ cout << fooRef; // Prints "I am foo. Hi!" // Doesn't reassign "fooRef". This is the same as "foo = bar", and // foo == "I am bar" // after this line. +cout << &fooRef << endl; //Prints address of fooRef 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. // Like C, const values (and pointers and references) cannot be modified. -- cgit v1.2.3 From 87e8e77e5fd8d84a252dbb6d6697202118378774 Mon Sep 17 00:00:00 2001 From: Pushkar Sharma Date: Mon, 5 Oct 2015 00:13:54 +0530 Subject: Fixed a mistake from previous commit. Better explained reference address. --- c++.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'c++.html.markdown') diff --git a/c++.html.markdown b/c++.html.markdown index bbd2f9a9..bd86e9e5 100644 --- a/c++.html.markdown +++ b/c++.html.markdown @@ -245,9 +245,9 @@ cout << fooRef; // Prints "I am foo. Hi!" // Doesn't reassign "fooRef". This is the same as "foo = bar", and // foo == "I am bar" // after this line. -cout << &fooRef << endl; //Prints address of fooRef +cout << &fooRef << endl; //Prints address of foo fooRef = bar; -cout << &fooRef << endl; //Prints address of fooRef, AGAIN +cout << &fooRef << endl; //Still prints address of foo cout << fooRef; // Prints "I am bar" //The address of fooRef remains the same, i.e. it is still referring to foo. -- cgit v1.2.3 From 3b246fd869564b0a7f7c847f44aecac82d318c78 Mon Sep 17 00:00:00 2001 From: Pushkar Sharma Date: Mon, 5 Oct 2015 00:32:34 +0530 Subject: Grammar the address --- c++.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'c++.html.markdown') diff --git a/c++.html.markdown b/c++.html.markdown index bd86e9e5..8ee964ca 100644 --- a/c++.html.markdown +++ b/c++.html.markdown @@ -245,9 +245,9 @@ cout << fooRef; // Prints "I am foo. Hi!" // Doesn't reassign "fooRef". This is the same as "foo = bar", and // foo == "I am bar" // after this line. -cout << &fooRef << endl; //Prints address of foo +cout << &fooRef << endl; //Prints the address of foo fooRef = bar; -cout << &fooRef << endl; //Still prints address of foo +cout << &fooRef << endl; //Still prints the address of foo cout << fooRef; // Prints "I am bar" //The address of fooRef remains the same, i.e. it is still referring to foo. -- cgit v1.2.3