<?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.8 &#8212; Pointers, arrays, and pointer arithmetic</title>
	<atom:link href="http://www.learncpp.com/cpp-tutorial/68-pointers-arrays-and-pointer-arithmetic/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.learncpp.com/cpp-tutorial/68-pointers-arrays-and-pointer-arithmetic/</link>
	<description></description>
	<pubDate>Fri, 29 Aug 2008 19:45:51 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: Savenaca Yauyau</title>
		<link>http://www.learncpp.com/cpp-tutorial/68-pointers-arrays-and-pointer-arithmetic/#comment-23671</link>
		<dc:creator>Savenaca Yauyau</dc:creator>
		<pubDate>Thu, 14 Aug 2008 08:01:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/68-pointers-arrays-and-pointer-arithmetic/#comment-23671</guid>
		<description>I am thankfull for above Information.I am doing C++ programming...and am doing a Project In Multiple Arrays, using Functions.

Hope To Get More Information in this web.

Thank you very much

Savenaca yauyau</description>
		<content:encoded><![CDATA[<p>I am thankfull for above Information.I am doing C++ programming&#8230;and am doing a Project In Multiple Arrays, using Functions.</p>
<p>Hope To Get More Information in this web.</p>
<p>Thank you very much</p>
<p>Savenaca yauyau</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stuart</title>
		<link>http://www.learncpp.com/cpp-tutorial/68-pointers-arrays-and-pointer-arithmetic/#comment-17269</link>
		<dc:creator>Stuart</dc:creator>
		<pubDate>Thu, 22 May 2008 21:28:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/68-pointers-arrays-and-pointer-arithmetic/#comment-17269</guid>
		<description>It's okay - I've come back to it with a clear head and I get it now. (And I realize that nArraySize-2 works.) :)

Thanks for tutorials, BTW.</description>
		<content:encoded><![CDATA[<p>It&#8217;s okay - I&#8217;ve come back to it with a clear head and I get it now. (And I realize that nArraySize-2 works.) :)</p>
<p>Thanks for tutorials, BTW.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stuart</title>
		<link>http://www.learncpp.com/cpp-tutorial/68-pointers-arrays-and-pointer-arithmetic/#comment-17259</link>
		<dc:creator>Stuart</dc:creator>
		<pubDate>Thu, 22 May 2008 19:41:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/68-pointers-arrays-and-pointer-arithmetic/#comment-17259</guid>
		<description>This is going over my head:
&lt;pre&gt;for (char *pnPtr = szName; pnPtr &#60;= szName + nArraySize; pnPtr++)&lt;/pre&gt;
Could you explain it, please?</description>
		<content:encoded><![CDATA[<p>This is going over my head:</p>
<pre>for (char *pnPtr = szName; pnPtr &lt;= szName + nArraySize; pnPtr++)</pre>
<p>Could you explain it, please?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Learn C++ - &#187; 6.7 &#8212; Introduction to pointers</title>
		<link>http://www.learncpp.com/cpp-tutorial/68-pointers-arrays-and-pointer-arithmetic/#comment-13478</link>
		<dc:creator>Learn C++ - &#187; 6.7 &#8212; Introduction to pointers</dc:creator>
		<pubDate>Tue, 29 Apr 2008 04:53:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/68-pointers-arrays-and-pointer-arithmetic/#comment-13478</guid>
		<description>[...] 2007      Prev/Next Posts   &#171; A PHP script to unzip files with file overwriting &#124; Home &#124; 6.8 &#8212; Pointers, arrays, and pointer arithmetic &#187;     Tuesday, July 10th, 2007 at 6:52 [...]</description>
		<content:encoded><![CDATA[<p>[...] 2007      Prev/Next Posts   &laquo; A PHP script to unzip files with file overwriting | Home | 6.8 &#8212; Pointers, arrays, and pointer arithmetic &raquo;     Tuesday, July 10th, 2007 at 6:52 [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://www.learncpp.com/cpp-tutorial/68-pointers-arrays-and-pointer-arithmetic/#comment-10964</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Sat, 05 Apr 2008 03:59:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/68-pointers-arrays-and-pointer-arithmetic/#comment-10964</guid>
		<description>When I ran your Lazy Brown Fox example with Visual C++ 2005, I got 3 vowels, not 4.  So at the moment I'm not sure why you're getting a different result.

My advise to you would be to run your program using a debugger, and step through the code.  Put a watch on nVowels and then watch it count up -- when it becomes 4, you'll at least know what's causing it.</description>
		<content:encoded><![CDATA[<p>When I ran your Lazy Brown Fox example with Visual C++ 2005, I got 3 vowels, not 4.  So at the moment I&#8217;m not sure why you&#8217;re getting a different result.</p>
<p>My advise to you would be to run your program using a debugger, and step through the code.  Put a watch on nVowels and then watch it count up &#8212; when it becomes 4, you&#8217;ll at least know what&#8217;s causing it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pete</title>
		<link>http://www.learncpp.com/cpp-tutorial/68-pointers-arrays-and-pointer-arithmetic/#comment-10935</link>
		<dc:creator>Pete</dc:creator>
		<pubDate>Fri, 04 Apr 2008 19:31:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/68-pointers-arrays-and-pointer-arithmetic/#comment-10935</guid>
		<description>Alex,

Your site is wonderful, thanks for providing it.  I was editing some of the examples you provide to see what happens with the output and I noticed something I cannot explain.  When I substitute the following into your last example (Mollie/Vowels) I get the output 3, which makes sense.

&lt;pre&gt;
const int nArraySize = 14;
char szName[nArraySize] = "Lazy BrownFox";
&lt;/pre&gt;

But When I change the code to the below, the result becomes 4, which I do not understand.  It is as if the program is counting the last whitespace character as a vowel.  Can you explain this to me?

&lt;pre&gt;
const int nArraySize = 15;
char szName[nArraySize] = "Lazy Brown Fox";
&lt;/pre&gt;

BTW, I am using Cygwin with Dev-C++ and the GNU compilers.

Thanks and best regards,
Pete</description>
		<content:encoded><![CDATA[<p>Alex,</p>
<p>Your site is wonderful, thanks for providing it.  I was editing some of the examples you provide to see what happens with the output and I noticed something I cannot explain.  When I substitute the following into your last example (Mollie/Vowels) I get the output 3, which makes sense.</p>
<pre>
const int nArraySize = 14;
char szName[nArraySize] = &#8220;Lazy BrownFox&#8221;;
</pre>
<p>But When I change the code to the below, the result becomes 4, which I do not understand.  It is as if the program is counting the last whitespace character as a vowel.  Can you explain this to me?</p>
<pre>
const int nArraySize = 15;
char szName[nArraySize] = &#8220;Lazy Brown Fox&#8221;;
</pre>
<p>BTW, I am using Cygwin with Dev-C++ and the GNU compilers.</p>
<p>Thanks and best regards,<br />
Pete</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://www.learncpp.com/cpp-tutorial/68-pointers-arrays-and-pointer-arithmetic/#comment-5060</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Thu, 27 Dec 2007 23:33:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/68-pointers-arrays-and-pointer-arithmetic/#comment-5060</guid>
		<description>The author of those articles is right on some points and wrong on others.  However, I find his logic and examples to be quite misleading.  Rather than refute his arguments, instead, let me see if I can shed some light on the situation as I understand it.

Arrays and pointers are not strictly identical.    Although arrays are implemented using pointers, arrays also contain slightly more information.  When you create an array, the compiler has to keep track of how many elements the array has.  Otherwise, the compiler would not know how many elements to delete when it came time to delete[] the array.

With a non-dynamically allocated array, it's possible to see the actual size of the array:

&lt;code&gt;int anArray[5];  cout &lt;&lt; sizeof(anArray);&lt;/code&gt;

This program prints out 20 (assuming 4-byte integers).  This is the size of the array.

On the other hand:

&lt;code&gt;int *ptr = anArray;  cout &lt;&lt; sizeof(ptr); &lt;/code&gt;

prints 4.  This is the size of the pointer.

When you access an array through a pointer, you're accessing it in a slightly limited manner, because you lose access to the size and type information of the original array.  This can be a pain (because it means you have to store the size of the array in a separate variable) but that's about the extent of the practical consequences.

Note that for dynamically allocated arrays:

&lt;code&gt;int *pnArray = new int[5]&lt;/code&gt;

the new operator returns a pointer to the array, and that's all you ever have to work with.  You never get access to the actual array object.

Functionally, in terms of how you access an array, there is no real difference between accessing the elements of an actual array and accessing the elements of an array through a pointer.

So technically, it is correct that arrays and pointers aren't identical.  Pointers give you access to a limited subset of the array information.  Practically speaking, it's generally not even worth worrying about.</description>
		<content:encoded><![CDATA[<p>The author of those articles is right on some points and wrong on others.  However, I find his logic and examples to be quite misleading.  Rather than refute his arguments, instead, let me see if I can shed some light on the situation as I understand it.</p>
<p>Arrays and pointers are not strictly identical.    Although arrays are implemented using pointers, arrays also contain slightly more information.  When you create an array, the compiler has to keep track of how many elements the array has.  Otherwise, the compiler would not know how many elements to delete when it came time to delete[] the array.</p>
<p>With a non-dynamically allocated array, it&#8217;s possible to see the actual size of the array:</p>
<p><code>int anArray[5];  cout < < sizeof(anArray);</code></p>
<p>This program prints out 20 (assuming 4-byte integers).  This is the size of the array.</p>
<p>On the other hand:</p>
<p></code><code>int *ptr = anArray;  cout < < sizeof(ptr); </code></p>
<p>prints 4.  This is the size of the pointer.</p>
<p>When you access an array through a pointer, you&#8217;re accessing it in a slightly limited manner, because you lose access to the size and type information of the original array.  This can be a pain (because it means you have to store the size of the array in a separate variable) but that&#8217;s about the extent of the practical consequences.</p>
<p>Note that for dynamically allocated arrays:</p>
<p></code><code>int *pnArray = new int[5]</code></p>
<p>the new operator returns a pointer to the array, and that&#8217;s all you ever have to work with.  You never get access to the actual array object.</p>
<p>Functionally, in terms of how you access an array, there is no real difference between accessing the elements of an actual array and accessing the elements of an array through a pointer.</p>
<p>So technically, it is correct that arrays and pointers aren&#8217;t identical.  Pointers give you access to a limited subset of the array information.  Practically speaking, it&#8217;s generally not even worth worrying about.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jacob</title>
		<link>http://www.learncpp.com/cpp-tutorial/68-pointers-arrays-and-pointer-arithmetic/#comment-5058</link>
		<dc:creator>Jacob</dc:creator>
		<pubDate>Thu, 27 Dec 2007 21:43:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/68-pointers-arrays-and-pointer-arithmetic/#comment-5058</guid>
		<description>Hi Alex!

I've been learning C   from your tutorial - and I think it's really great, so thanks.
However I just wanted to point (speaking of pointers ;-)) out, that the guy behind these two articles 
www.cplusplus.com/articles/siavoshkc1.html
www.cplusplus.com/articles/Arrptr.html
would have to disagree with you on whether arrays and pointers are the same. Personally, I don't care if he is right, since the code presented here still works intentionally.

Best regards
Jacob</description>
		<content:encoded><![CDATA[<p>Hi Alex!</p>
<p>I&#8217;ve been learning C   from your tutorial - and I think it&#8217;s really great, so thanks.<br />
However I just wanted to point (speaking of pointers ;-)) out, that the guy behind these two articles<br />
<a href="http://www.cplusplus.com/articles/siavoshkc1.html" rel="nofollow">http://www.cplusplus.com/articles/siavoshkc1.html</a><br />
<a href="http://www.cplusplus.com/articles/Arrptr.html" rel="nofollow">http://www.cplusplus.com/articles/Arrptr.html</a><br />
would have to disagree with you on whether arrays and pointers are the same. Personally, I don&#8217;t care if he is right, since the code presented here still works intentionally.</p>
<p>Best regards<br />
Jacob</p>
]]></content:encoded>
	</item>
</channel>
</rss>
