<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Index von 3D Array]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe ein Array der Dimension 100*100*50. Nun möchte ich durch alle Elemente iterieren und habe es so versucht:</p>
<pre><code>int data[100*100*50;
for (int x = 0; x &lt; 100; ++x)
    for (int y = 0; y &lt; 100; ++y)
        for (int z = 0; z &lt; 50; ++z)
            data[x + y * 100 + z * 100 * 50] = 0; // x + y * width + z * width * depth
</code></pre>
<p>So findet man es auch in allen einschlägigen Quellen.<br />
Wenn ich jetzt aber nachrechne, welcher der maximal erreichbare Index ist dann komme ich auf</p>
<pre><code>99 + 99 * 100 + 49 * 100 * 49 = 254999 != 499999
</code></pre>
<p>Das Array hat aber 500000 Elemente. Bin ich jetzt vollkommen auf den Kopf gefallen, was ist hier falsch?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/331897/index-von-3d-array</link><generator>RSS for Node</generator><lastBuildDate>Wed, 29 Apr 2026 01:55:46 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/331897.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 27 Mar 2015 12:28:45 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Index von 3D Array on Fri, 27 Mar 2015 12:28:45 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe ein Array der Dimension 100*100*50. Nun möchte ich durch alle Elemente iterieren und habe es so versucht:</p>
<pre><code>int data[100*100*50;
for (int x = 0; x &lt; 100; ++x)
    for (int y = 0; y &lt; 100; ++y)
        for (int z = 0; z &lt; 50; ++z)
            data[x + y * 100 + z * 100 * 50] = 0; // x + y * width + z * width * depth
</code></pre>
<p>So findet man es auch in allen einschlägigen Quellen.<br />
Wenn ich jetzt aber nachrechne, welcher der maximal erreichbare Index ist dann komme ich auf</p>
<pre><code>99 + 99 * 100 + 49 * 100 * 49 = 254999 != 499999
</code></pre>
<p>Das Array hat aber 500000 Elemente. Bin ich jetzt vollkommen auf den Kopf gefallen, was ist hier falsch?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2448187</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2448187</guid><dc:creator><![CDATA[Kopffaller]]></dc:creator><pubDate>Fri, 27 Mar 2015 12:28:45 GMT</pubDate></item><item><title><![CDATA[Reply to Index von 3D Array on Fri, 27 Mar 2015 12:40:36 GMT]]></title><description><![CDATA[<p>Kopffaller schrieb:</p>
<blockquote>
<p>Das Array hat aber 500000 Elemente. Bin ich jetzt vollkommen auf den Kopf gefallen, was ist hier falsch?</p>
</blockquote>
<p>Nichts - 0...499999 sind 500000 Elemente.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2448190</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2448190</guid><dc:creator><![CDATA[MichelRT]]></dc:creator><pubDate>Fri, 27 Mar 2015 12:40:36 GMT</pubDate></item><item><title><![CDATA[Reply to Index von 3D Array on Fri, 27 Mar 2015 12:44:29 GMT]]></title><description><![CDATA[<p>Wie ich erwähnte ist der höchste Index den ich erreiche 254999.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2448191</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2448191</guid><dc:creator><![CDATA[Kopffaller]]></dc:creator><pubDate>Fri, 27 Mar 2015 12:44:29 GMT</pubDate></item><item><title><![CDATA[Reply to Index von 3D Array on Fri, 27 Mar 2015 12:52:46 GMT]]></title><description><![CDATA[<p><code>99 + 99 * 100 + 49 * 100 * 100 = 499999</code></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2448194</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2448194</guid><dc:creator><![CDATA[Caligulaminus]]></dc:creator><pubDate>Fri, 27 Mar 2015 12:52:46 GMT</pubDate></item><item><title><![CDATA[Reply to Index von 3D Array on Fri, 27 Mar 2015 13:02:47 GMT]]></title><description><![CDATA[<pre><code>data[x + y * 100 + z * 100 * 50] = 0; // x + y * width + z * width * depth
</code></pre>
<p>Ist auch falsch.</p>
<pre><code>data[x + y * 100 + z * 100 * 100] = 0; // x + y * width + z * width * height
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2448196</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2448196</guid><dc:creator><![CDATA[MichelRT]]></dc:creator><pubDate>Fri, 27 Mar 2015 13:02:47 GMT</pubDate></item></channel></rss>