<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: 6.11 &#8212; References</title>
	<atom:link href="http://www.learncpp.com/cpp-tutorial/611-references/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.learncpp.com/cpp-tutorial/611-references/</link>
	<description></description>
	<pubDate>Fri, 29 Aug 2008 19:59:41 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: dlt123</title>
		<link>http://www.learncpp.com/cpp-tutorial/611-references/#comment-22017</link>
		<dc:creator>dlt123</dc:creator>
		<pubDate>Sat, 26 Jul 2008 19:18:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-programming/611-references-2/#comment-22017</guid>
		<description>Alex, just another happy and impressed reader of your C++ Tutorials.  I've been reading the  book C++ Primer Plus and it's a good book, but it sometimes overwhelms the student with too much information on what's being taught and not on what needs to be learned.

Your Tutorial is in my opinion far superior to C++ PP.  It has really helped me get a better grasp of this language.

Thank you for bringing the human element to this tutorial and making it easier to understand.

Note: You should consider making this Tutorial into a book.  It's better than what I've seen being offered out in the world.

Take care and best of luck in your endeavors.

Dennis</description>
		<content:encoded><![CDATA[<p>Alex, just another happy and impressed reader of your C++ Tutorials.  I&#8217;ve been reading the  book C++ Primer Plus and it&#8217;s a good book, but it sometimes overwhelms the student with too much information on what&#8217;s being taught and not on what needs to be learned.</p>
<p>Your Tutorial is in my opinion far superior to C++ PP.  It has really helped me get a better grasp of this language.</p>
<p>Thank you for bringing the human element to this tutorial and making it easier to understand.</p>
<p>Note: You should consider making this Tutorial into a book.  It&#8217;s better than what I&#8217;ve seen being offered out in the world.</p>
<p>Take care and best of luck in your endeavors.</p>
<p>Dennis</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: srinivas</title>
		<link>http://www.learncpp.com/cpp-tutorial/611-references/#comment-22003</link>
		<dc:creator>srinivas</dc:creator>
		<pubDate>Sat, 26 Jul 2008 16:12:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-programming/611-references-2/#comment-22003</guid>
		<description>Hi alex,
doing great job .
i am fresher attending campus placement.
please mention which topics in C++ needs to be focussed from interview point of view.
also post some tricky questions associated with c++ and reference variables which wil be useful for us in interview.


continue job for welfare of programmers!!!!!!!!!!!!!!!!!!</description>
		<content:encoded><![CDATA[<p>Hi alex,<br />
doing great job .<br />
i am fresher attending campus placement.<br />
please mention which topics in C++ needs to be focussed from interview point of view.<br />
also post some tricky questions associated with c++ and reference variables which wil be useful for us in interview.</p>
<p>continue job for welfare of programmers!!!!!!!!!!!!!!!!!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: el-mudo</title>
		<link>http://www.learncpp.com/cpp-tutorial/611-references/#comment-20549</link>
		<dc:creator>el-mudo</dc:creator>
		<pubDate>Tue, 08 Jul 2008 19:26:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-programming/611-references-2/#comment-20549</guid>
		<description>Hey Alex, I would like to thank you for the GREAT tutorial. It's been very useful for me so far in migrating from C and the simple (very human) language makes it easy to understand even for people with no coding experience

And good point in the comment up here, i'm pleased to see i'm learning from someone who realy knows what he's talking about xD

Now, when somebody asks me where to learn cplusplus, it's your site I'll recomend (unfortunately most pleople I know wont be very pleased to have to translate it so then can understand)

keep the good work!

(eh, sorry for the bad english)</description>
		<content:encoded><![CDATA[<p>Hey Alex, I would like to thank you for the GREAT tutorial. It&#8217;s been very useful for me so far in migrating from C and the simple (very human) language makes it easy to understand even for people with no coding experience</p>
<p>And good point in the comment up here, i&#8217;m pleased to see i&#8217;m learning from someone who realy knows what he&#8217;s talking about xD</p>
<p>Now, when somebody asks me where to learn cplusplus, it&#8217;s your site I&#8217;ll recomend (unfortunately most pleople I know wont be very pleased to have to translate it so then can understand)</p>
<p>keep the good work!</p>
<p>(eh, sorry for the bad english)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Learn C++ - &#187; 6.10 &#8212; Pointers and const</title>
		<link>http://www.learncpp.com/cpp-tutorial/611-references/#comment-13482</link>
		<dc:creator>Learn C++ - &#187; 6.10 &#8212; Pointers and const</dc:creator>
		<pubDate>Tue, 29 Apr 2008 04:55:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-programming/611-references-2/#comment-13482</guid>
		<description>[...]      Prev/Next Posts   &#171; 6.9 &#8212; Dynamic memory allocation with new and delete &#124; Home &#124; 6.11 &#8212; References &#187;     Monday, July 16th, 2007 at 1:40 [...]</description>
		<content:encoded><![CDATA[<p>[...]      Prev/Next Posts   &laquo; 6.9 &#8212; Dynamic memory allocation with new and delete | Home | 6.11 &#8212; References &raquo;     Monday, July 16th, 2007 at 1:40 [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://www.learncpp.com/cpp-tutorial/611-references/#comment-7231</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Mon, 04 Feb 2008 20:56:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-programming/611-references-2/#comment-7231</guid>
		<description>When you allocate local variables, they are put on the stack.  Because of the way stacks work, variables allocated sequentially should be laid out sequentially in memory.  For example:

&lt;pre&gt;
int x;
cout &lt;&lt; &#038;x &lt;&lt; endl;
int y;
cout &lt;&lt; &#038;y &lt;&lt; endl;
int z;
cout &lt;&lt; &#038;z &lt;&lt; endl;
&lt;/pre&gt;

produces the result:
0012FF7C
0012FF78
0012FF74

As you can see, the first thing allocated was put in 0012FF7C, the second in 0012FF78, and the third in 0012FF74.

In the first example above, we allocate one variable (nRef), so it gets allocated to 0012FF7C as we would expect.

The second example is more interesting.  In the second example above, we allocate one reference (rnRef)... When we take the address of a reference, it returns the address of whatever it's referencing (not it's actual address).  &#038;rnRef returns 0012FF78, which is the second spot available for allocation.  If the thing rnRef is pointing to is in the second spot available for allocation, then what's in the first spot?

The answer is the reference itself!

If this is true, then the value at address 0012FF7C (which is where the reference actually lives) should be the address 0012FF78 (which is what the reference is pointing at).  If we look at the value in memory address 0012FF7C (using a debugger), we see the decimal value 1245048, which is 0012FF78 in hex.

So it appears the theory is true.  The reference itself is being allocated at memory 0012FF7C.  It contains the value 0012FF78, which is what the reference is looking at.  Memory 0012FF78 has the value 6.  The literal value 6 was given it's own memory address so the reference could point to it.</description>
		<content:encoded><![CDATA[<p>When you allocate local variables, they are put on the stack.  Because of the way stacks work, variables allocated sequentially should be laid out sequentially in memory.  For example:</p>
<pre>
int x;
cout < < &#038;x << endl;
int y;
cout << &#038;y << endl;
int z;
cout << &#038;z << endl;
</pre>
<p>produces the result:<br />
0012FF7C<br />
0012FF78<br />
0012FF74</p>
<p>As you can see, the first thing allocated was put in 0012FF7C, the second in 0012FF78, and the third in 0012FF74.</p>
<p>In the first example above, we allocate one variable (nRef), so it gets allocated to 0012FF7C as we would expect.</p>
<p>The second example is more interesting.  In the second example above, we allocate one reference (rnRef)&#8230; When we take the address of a reference, it returns the address of whatever it&#8217;s referencing (not it&#8217;s actual address).  &#038;rnRef returns 0012FF78, which is the second spot available for allocation.  If the thing rnRef is pointing to is in the second spot available for allocation, then what&#8217;s in the first spot?</p>
<p>The answer is the reference itself!</p>
<p>If this is true, then the value at address 0012FF7C (which is where the reference actually lives) should be the address 0012FF78 (which is what the reference is pointing at).  If we look at the value in memory address 0012FF7C (using a debugger), we see the decimal value 1245048, which is 0012FF78 in hex.</p>
<p>So it appears the theory is true.  The reference itself is being allocated at memory 0012FF7C.  It contains the value 0012FF78, which is what the reference is looking at.  Memory 0012FF78 has the value 6.  The literal value 6 was given it&#8217;s own memory address so the reference could point to it.</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zafer</title>
		<link>http://www.learncpp.com/cpp-tutorial/611-references/#comment-7219</link>
		<dc:creator>Zafer</dc:creator>
		<pubDate>Mon, 04 Feb 2008 18:38:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-programming/611-references-2/#comment-7219</guid>
		<description>Yes this theory is meaningful. I don't see however how the second allocation is doing an extra allocation.</description>
		<content:encoded><![CDATA[<p>Yes this theory is meaningful. I don&#8217;t see however how the second allocation is doing an extra allocation.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://www.learncpp.com/cpp-tutorial/611-references/#comment-7214</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Mon, 04 Feb 2008 17:46:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-programming/611-references-2/#comment-7214</guid>
		<description>This is a very interesting point, and one for which I can not give you a definitive answer.  References are typically implemented using pointers, and pointers must point to an address, which implies the other author is correct in that regard.  On the other hand, you can experimentally determine that the above code does indeed compile and perform as expected!  As you note, there is a seeming inconsistency between these two things.

My guess is that the compiler promotes the literal 6 to a constant int, and then assigns the reference to that.  To see if I could find any evidence of this behavior, I did a simple test:

&lt;pre&gt;
const int nRef = 6;
cout &lt;&lt; &#038;nRef &lt;&lt; endl;
&lt;/pre&gt;

On my machine, this prints 0012FF7C

&lt;pre&gt;
const int &#038;rnRef = 6;
cout &lt;&lt; &#038;rnRef &lt;&lt; endl;
&lt;/pre&gt;

On my machine, this prints 0012FF78

With integers being 4 bytes, note that the second example appears to be doing an extra allocation.  This certainly lends support to the theory of the literal being promoted to a constant integer.</description>
		<content:encoded><![CDATA[<p>This is a very interesting point, and one for which I can not give you a definitive answer.  References are typically implemented using pointers, and pointers must point to an address, which implies the other author is correct in that regard.  On the other hand, you can experimentally determine that the above code does indeed compile and perform as expected!  As you note, there is a seeming inconsistency between these two things.</p>
<p>My guess is that the compiler promotes the literal 6 to a constant int, and then assigns the reference to that.  To see if I could find any evidence of this behavior, I did a simple test:</p>
<pre>
const int nRef = 6;
cout < < &#038;nRef << endl;
</pre>
<p>On my machine, this prints 0012FF7C</p>
</pre>
<pre>
const int &#038;rnRef = 6;
cout < < &#038;rnRef << endl;
</pre>
<p>On my machine, this prints 0012FF78</p>
<p>With integers being 4 bytes, note that the second example appears to be doing an extra allocation.  This certainly lends support to the theory of the literal being promoted to a constant integer.</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zafer</title>
		<link>http://www.learncpp.com/cpp-tutorial/611-references/#comment-7209</link>
		<dc:creator>Zafer</dc:creator>
		<pubDate>Mon, 04 Feb 2008 16:44:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-programming/611-references-2/#comment-7209</guid>
		<description>I have a question about the statement: "You can assign const references to literal values, though there is typically not much need to do so: const int &#38;rnRef = 6;"

In another tutorial, I read that a reference variable needs an accessable address. When we declare a reference variable we can only assign something that has a valid address. In other words, the thing we are assigning should be an l-value. However, constant literals do not have predefined memory address therefore cannot be assigned to a reference variable. Please correct me if I'm wrong.</description>
		<content:encoded><![CDATA[<p>I have a question about the statement: &#8220;You can assign const references to literal values, though there is typically not much need to do so: const int &amp;rnRef = 6;&#8221;</p>
<p>In another tutorial, I read that a reference variable needs an accessable address. When we declare a reference variable we can only assign something that has a valid address. In other words, the thing we are assigning should be an l-value. However, constant literals do not have predefined memory address therefore cannot be assigned to a reference variable. Please correct me if I&#8217;m wrong.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://www.learncpp.com/cpp-tutorial/611-references/#comment-7026</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Fri, 01 Feb 2008 07:08:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-programming/611-references-2/#comment-7026</guid>
		<description>There is a difference between a reference and a const reference.  A reference will let you change the value the reference points to, whereas a const reference will not.  However, all references are "const" in the sense that you can not change what the reference points to.</description>
		<content:encoded><![CDATA[<p>There is a difference between a reference and a const reference.  A reference will let you change the value the reference points to, whereas a const reference will not.  However, all references are &#8220;const&#8221; in the sense that you can not change what the reference points to.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sumtaru</title>
		<link>http://www.learncpp.com/cpp-tutorial/611-references/#comment-7020</link>
		<dc:creator>sumtaru</dc:creator>
		<pubDate>Fri, 01 Feb 2008 06:14:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-programming/611-references-2/#comment-7020</guid>
		<description>In C++ reference means constant reference. 
To the best of my knowledge there is no difference between reference and constant reference.</description>
		<content:encoded><![CDATA[<p>In C++ reference means constant reference.<br />
To the best of my knowledge there is no difference between reference and constant reference.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
