<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: 7.4a &#8212; Returning values by value, reference, and address</title>
	<atom:link href="http://www.learncpp.com/cpp-tutorial/74a-returning-values-by-value-reference-and-address/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.learncpp.com/cpp-tutorial/74a-returning-values-by-value-reference-and-address/</link>
	<description></description>
	<lastBuildDate>Tue, 07 Feb 2012 12:30:29 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: dimonic</title>
		<link>http://www.learncpp.com/cpp-tutorial/74a-returning-values-by-value-reference-and-address/comment-page-1/#comment-95468</link>
		<dc:creator>dimonic</dc:creator>
		<pubDate>Wed, 18 May 2011 13:17:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/74a-returning-values-by-value-reference-and-address/#comment-95468</guid>
		<description>Excuse the late reply - I found this from a google search.

Isn&#039;t it more likely the c++ runtime that deletes arrays? So the compiler cannot tell how big an allocated array will be (becuase it can be allocated by a variable amount). So if you want an array you can tell the siz of, you should use an stl vector.</description>
		<content:encoded><![CDATA[<p>Excuse the late reply &#8211; I found this from a google search.</p>
<p>Isn&#8217;t it more likely the c++ runtime that deletes arrays? So the compiler cannot tell how big an allocated array will be (becuase it can be allocated by a variable amount). So if you want an array you can tell the siz of, you should use an stl vector.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mccp13</title>
		<link>http://www.learncpp.com/cpp-tutorial/74a-returning-values-by-value-reference-and-address/comment-page-1/#comment-95389</link>
		<dc:creator>mccp13</dc:creator>
		<pubDate>Tue, 26 Apr 2011 09:34:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/74a-returning-values-by-value-reference-and-address/#comment-95389</guid>
		<description>what does the int&amp; mean in pankaj&#039;s function int&amp; multiply(int, int)..
does it mean it returns the address of an integer or a reference to an integer..
and how did the local variable res1 int his main function accept the return type if the function? 

Nice Tutorial btw.. i&#039;m using this to learn c++ :)</description>
		<content:encoded><![CDATA[<p>what does the int&amp; mean in pankaj&#8217;s function int&amp; multiply(int, int)..<br />
does it mean it returns the address of an integer or a reference to an integer..<br />
and how did the local variable res1 int his main function accept the return type if the function? </p>
<p>Nice Tutorial btw.. i&#8217;m using this to learn c++ :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: zzeroo</title>
		<link>http://www.learncpp.com/cpp-tutorial/74a-returning-values-by-value-reference-and-address/comment-page-1/#comment-95100</link>
		<dc:creator>zzeroo</dc:creator>
		<pubDate>Sun, 16 Jan 2011 13:04:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/74a-returning-values-by-value-reference-and-address/#comment-95100</guid>
		<description>Hey Alex,

great tutorial! It&#039;s so amazing simple to learn C with your help, I&#039;ve never thought before.

I&#039;ve found a little error he links aren’t correct:
&lt;pre&gt;« 7.14 — Ellipses (and why to avoid them)  
  13.1 — Input and output (I/O) streams »&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Hey Alex,</p>
<p>great tutorial! It&#8217;s so amazing simple to learn C with your help, I&#8217;ve never thought before.</p>
<p>I&#8217;ve found a little error he links aren’t correct:</p>
<pre>« 7.14 — Ellipses (and why to avoid them)
  13.1 — Input and output (I/O) streams »</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: vamsi</title>
		<link>http://www.learncpp.com/cpp-tutorial/74a-returning-values-by-value-reference-and-address/comment-page-1/#comment-93789</link>
		<dc:creator>vamsi</dc:creator>
		<pubDate>Fri, 15 Oct 2010 10:25:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/74a-returning-values-by-value-reference-and-address/#comment-93789</guid>
		<description>&lt;pre&gt;
Alex,

Can you start STL tutorials
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<pre>
Alex,

Can you start STL tutorials
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: abcd</title>
		<link>http://www.learncpp.com/cpp-tutorial/74a-returning-values-by-value-reference-and-address/comment-page-1/#comment-90094</link>
		<dc:creator>abcd</dc:creator>
		<pubDate>Thu, 12 Aug 2010 05:00:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/74a-returning-values-by-value-reference-and-address/#comment-90094</guid>
		<description>My guess is, since apArray was not created using &lt;pre&gt;new int[]&lt;/pre&gt; but rather something like &lt;pre&gt;int* apArray = int* npPtr&lt;/pre&gt;

it is most likely that the compiler does not take it as an Array.
Try this: &lt;pre&gt;delete apArray&lt;/pre&gt;
Then access to any element will result in garbage
&lt;pre&gt;std::cout &lt;&lt;  apArray[0];&lt;/pre&gt;

Once again, this is my guess. Hopefully Alex or someone else can verify this.

BTW, great tutorial Alex! Thanks a ton.</description>
		<content:encoded><![CDATA[<p>My guess is, since apArray was not created using
<pre>new int[]</pre>
<p> but rather something like
<pre>int* apArray = int* npPtr</pre>
<p>it is most likely that the compiler does not take it as an Array.<br />
Try this:
<pre>delete apArray</pre>
<p>Then access to any element will result in garbage</p>
<pre>std::cout &lt;&lt;  apArray[0];</pre>
<p>Once again, this is my guess. Hopefully Alex or someone else can verify this.</p>
<p>BTW, great tutorial Alex! Thanks a ton.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ellankavi</title>
		<link>http://www.learncpp.com/cpp-tutorial/74a-returning-values-by-value-reference-and-address/comment-page-1/#comment-89181</link>
		<dc:creator>ellankavi</dc:creator>
		<pubDate>Tue, 27 Jul 2010 14:20:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/74a-returning-values-by-value-reference-and-address/#comment-89181</guid>
		<description>Hello!
In the following code, is the dynamic array deleted properly?
&lt;pre&gt;
#include&lt;iostream&gt;

int* CreateArray(int nSize)
{
	int* const npPtr = new int[nSize];

	//initialize the array
	for (int iii=0;iii&lt;nSize;iii++)
		npPtr[iii]=iii;
	return npPtr;
}

int main()
{
	int nSize=5;
	int *apArray=CreateArray(nSize);
	delete[] apArray;
	system(&quot;pause&quot;);
	return 0;
}
&lt;/pre&gt;

Thanks :)</description>
		<content:encoded><![CDATA[<p>Hello!<br />
In the following code, is the dynamic array deleted properly?</p>
<pre>
#include&lt;iostream&gt;

int* CreateArray(int nSize)
{
	int* const npPtr = new int[nSize];

	//initialize the array
	for (int iii=0;iii&lt;nSize;iii++)
		npPtr[iii]=iii;
	return npPtr;
}

int main()
{
	int nSize=5;
	int *apArray=CreateArray(nSize);
	delete[] apArray;
	system(&quot;pause&quot;);
	return 0;
}
</pre>
<p>Thanks :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anna</title>
		<link>http://www.learncpp.com/cpp-tutorial/74a-returning-values-by-value-reference-and-address/comment-page-1/#comment-87705</link>
		<dc:creator>Anna</dc:creator>
		<pubDate>Sat, 03 Jul 2010 03:56:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/74a-returning-values-by-value-reference-and-address/#comment-87705</guid>
		<description>&lt;pre&gt;
But you can not be sure of how long that value exists and how 
long you can use that variable. Actually when you are 
returning from that function, the scope of that variable does 
not exist, but in memory there exists such an address and a 
value since nobody changes it. but there is a chance that 
when a new memory allocation is done by our process, the OS 
takes this memory and gives it.that time the value at this 
particular address might have changed and we may not be 
getting what we are expecting. in very simple terms using 
such a variable is just unsafe like using a property that we 
already sold. when the new owner comes you have to give it 
to that person and stop using it. but you never know when.
such usage is very unsafe with big programs having multiple
threads
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<pre>
But you can not be sure of how long that value exists and how
long you can use that variable. Actually when you are
returning from that function, the scope of that variable does
not exist, but in memory there exists such an address and a
value since nobody changes it. but there is a chance that
when a new memory allocation is done by our process, the OS
takes this memory and gives it.that time the value at this
particular address might have changed and we may not be
getting what we are expecting. in very simple terms using
such a variable is just unsafe like using a property that we
already sold. when the new owner comes you have to give it
to that person and stop using it. but you never know when.
such usage is very unsafe with big programs having multiple
threads
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: haya</title>
		<link>http://www.learncpp.com/cpp-tutorial/74a-returning-values-by-value-reference-and-address/comment-page-1/#comment-85183</link>
		<dc:creator>haya</dc:creator>
		<pubDate>Sat, 22 May 2010 08:00:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/74a-returning-values-by-value-reference-and-address/#comment-85183</guid>
		<description>suppose i have to write one function to give me the highest and lowest and average how i will write it without using void?
by using refrence but how?</description>
		<content:encoded><![CDATA[<p>suppose i have to write one function to give me the highest and lowest and average how i will write it without using void?<br />
by using refrence but how?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pankaj</title>
		<link>http://www.learncpp.com/cpp-tutorial/74a-returning-values-by-value-reference-and-address/comment-page-1/#comment-75349</link>
		<dc:creator>pankaj</dc:creator>
		<pubDate>Sat, 02 Jan 2010 17:36:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/74a-returning-values-by-value-reference-and-address/#comment-75349</guid>
		<description>I try to return the value of the local variable by using return by reference. It is possible to do that.
I am getting the correct values.
Compiler is only giving waring...warning C4172: returning address of local variable or temporary

plese see the code below and kindly give your comments..
&lt;pre&gt;


result of below code is 

Hello World!
res = 7 
res1 = 12

int add (int x, int y)
{
int result = x+y;
return result;
}

// return by reference 
int&amp; multiply(int x, int y)
{
 int result = x*y;
 return result;
}

int main(int argc, char* argv[])
{
	printf(&quot;Hello World!\n&quot;);
	int res = add(3,4);
	std::cout&lt;&lt; &quot;res = &quot; &lt;&lt; res &lt;&lt; std::endl; 

	int res1 = multiply(3,4);
	std::cout &lt;&lt; &quot;res1 = &quot; &lt;&lt; res1 &lt;&lt; std::endl; 
	return 0;
}

&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>I try to return the value of the local variable by using return by reference. It is possible to do that.<br />
I am getting the correct values.<br />
Compiler is only giving waring&#8230;warning C4172: returning address of local variable or temporary</p>
<p>plese see the code below and kindly give your comments..</p>
<pre>

result of below code is 

Hello World!
res = 7
res1 = 12

int add (int x, int y)
{
int result = x+y;
return result;
}

// return by reference
int&amp; multiply(int x, int y)
{
 int result = x*y;
 return result;
}

int main(int argc, char* argv[])
{
	printf(&quot;Hello World!\n&quot;);
	int res = add(3,4);
	std::cout&lt;&lt; &quot;res = &quot; &lt;&lt; res &lt;&lt; std::endl; 

	int res1 = multiply(3,4);
	std::cout &lt;&lt; &quot;res1 = &quot; &lt;&lt; res1 &lt;&lt; std::endl;
	return 0;
}
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kurt</title>
		<link>http://www.learncpp.com/cpp-tutorial/74a-returning-values-by-value-reference-and-address/comment-page-1/#comment-64328</link>
		<dc:creator>Kurt</dc:creator>
		<pubDate>Wed, 15 Jul 2009 04:06:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/74a-returning-values-by-value-reference-and-address/#comment-64328</guid>
		<description>A reference works like an alias for the original data. You&#039;re not changing the value of the reference itself, because references are in a sense immutable. You&#039;re changing the value of the data the reference aliases. It&#039;s like modifying the dereferenced value of a pointer.</description>
		<content:encoded><![CDATA[<p>A reference works like an alias for the original data. You&#8217;re not changing the value of the reference itself, because references are in a sense immutable. You&#8217;re changing the value of the data the reference aliases. It&#8217;s like modifying the dereferenced value of a pointer.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

