<?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[3-dim Arrays und Pointer]]></title><description><![CDATA[<p>Hallo meine Lieben,</p>
<p>ich schwimme total momentan, ich habe die aufgabe den code</p>
<pre><code class="language-cpp">// Program: threedim_array.C
// iterate over a multidimensional array
#include &lt;iostream&gt;

int main() 
{
  int a[4][2][3] = 
    { // the 4 elements of a:
      { // the 2 elements of a[0]:
	{2, 4, 5}, // the three elements of a[0][0]
	{4, 6, 7}  // the three elements of a[0][1]
      }, 
      { // the 2 elements of a[1]:
	{1, 5, 9}, // the three elements of a[1][0]
	{4, 6, 1}  // the three elements of a[1][1]
      }, 
      { // the 2 elements of a[2]:
	{5, 9, 0}, // the three elements of a[2][0]
	{1, 5, 3}  // the three elements of a[2][1]
      }, 
      { // the 2 elements of a[3]:
	{6, 7, 7}, // the three elements of a[3][0]
	{7, 8, 5}  // the three elements of a[3][1]
      } 
    }; 

  return 0;

}
</code></pre>
<p>so umzuschreiben, dass es über jeden array a und dessen subarrays iteriert und alle 24 zahlen der reihe nach ausgibt.</p>
<p>Das fiese daran ist, und das macht mir so zu schaffen, dass ich nicht den random acces benützen darf, sondern verschachtelte loops bauen muss, wobei auch sizeof() etc verboten sind. Also mit anderen Worten, Pointerarithemtik ist gefragt... leider sitzt di bei mir ganz und gar nicht...</p>
<p>ich hoffe, jemand kann mir helfen,</p>
<p>lg<br />
damian</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/198098/3-dim-arrays-und-pointer</link><generator>RSS for Node</generator><lastBuildDate>Thu, 01 Oct 2026 21:11:15 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/198098.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 18 Nov 2007 13:28:53 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to 3-dim Arrays und Pointer on Sun, 18 Nov 2007 13:28:53 GMT]]></title><description><![CDATA[<p>Hallo meine Lieben,</p>
<p>ich schwimme total momentan, ich habe die aufgabe den code</p>
<pre><code class="language-cpp">// Program: threedim_array.C
// iterate over a multidimensional array
#include &lt;iostream&gt;

int main() 
{
  int a[4][2][3] = 
    { // the 4 elements of a:
      { // the 2 elements of a[0]:
	{2, 4, 5}, // the three elements of a[0][0]
	{4, 6, 7}  // the three elements of a[0][1]
      }, 
      { // the 2 elements of a[1]:
	{1, 5, 9}, // the three elements of a[1][0]
	{4, 6, 1}  // the three elements of a[1][1]
      }, 
      { // the 2 elements of a[2]:
	{5, 9, 0}, // the three elements of a[2][0]
	{1, 5, 3}  // the three elements of a[2][1]
      }, 
      { // the 2 elements of a[3]:
	{6, 7, 7}, // the three elements of a[3][0]
	{7, 8, 5}  // the three elements of a[3][1]
      } 
    }; 

  return 0;

}
</code></pre>
<p>so umzuschreiben, dass es über jeden array a und dessen subarrays iteriert und alle 24 zahlen der reihe nach ausgibt.</p>
<p>Das fiese daran ist, und das macht mir so zu schaffen, dass ich nicht den random acces benützen darf, sondern verschachtelte loops bauen muss, wobei auch sizeof() etc verboten sind. Also mit anderen Worten, Pointerarithemtik ist gefragt... leider sitzt di bei mir ganz und gar nicht...</p>
<p>ich hoffe, jemand kann mir helfen,</p>
<p>lg<br />
damian</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1405281</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1405281</guid><dc:creator><![CDATA[Damian]]></dc:creator><pubDate>Sun, 18 Nov 2007 13:28:53 GMT</pubDate></item><item><title><![CDATA[Reply to 3-dim Arrays und Pointer on Sun, 18 Nov 2007 14:14:15 GMT]]></title><description><![CDATA[<p>Wir machen hier keine hausafgaben, also sage uns ein konkretes Problem zund was du bisher versucht hast.</p>
<p>Kleine Anregung: Nimm 3 ineinander verschachtelte for-schleifen und gib so die Werte aus...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1405315</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1405315</guid><dc:creator><![CDATA[The-Kenny]]></dc:creator><pubDate>Sun, 18 Nov 2007 14:14:15 GMT</pubDate></item><item><title><![CDATA[Reply to 3-dim Arrays und Pointer on Sun, 18 Nov 2007 14:42:54 GMT]]></title><description><![CDATA[<p>Wie gesagt: Der Tipp ist eine for-Schleife. Da du die Länge der einzelnen Arrays kennst, ist ein &quot;sizeof()&quot; sowieso überflüssig. Die Werte dann mittels Zeigerarithmetik statt Operatoraufruf auszugeben ist ein Leichtes, wenn du weißt, dass der Name des Arrays ein Zeiger auf das erste Element ist. Allerdings ist mir nicht klar, wieso die übliche Ausgabemethode mittels des []-Operators nicht erlaubt sein sollte.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1405328</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1405328</guid><dc:creator><![CDATA[moagnus]]></dc:creator><pubDate>Sun, 18 Nov 2007 14:42:54 GMT</pubDate></item><item><title><![CDATA[Reply to 3-dim Arrays und Pointer on Sun, 18 Nov 2007 14:51:18 GMT]]></title><description><![CDATA[<p>Einfach drei ineinander geschachtelte for-Schleifen mit einem Zeiger auf das erste Element.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1405336</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1405336</guid><dc:creator><![CDATA[*D*]]></dc:creator><pubDate>Sun, 18 Nov 2007 14:51:18 GMT</pubDate></item><item><title><![CDATA[Reply to 3-dim Arrays und Pointer on Sun, 18 Nov 2007 15:04:28 GMT]]></title><description><![CDATA[<p>p[1] ist äquivalent zu *(p + 1), also wäre p[1][2] z.b. äquivalent zu <em>(</em>(p + 1) + 2)</p>
<p>von hier gehts hoffentlich von allein <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1405348</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1405348</guid><dc:creator><![CDATA[thordk]]></dc:creator><pubDate>Sun, 18 Nov 2007 15:04:28 GMT</pubDate></item><item><title><![CDATA[Reply to 3-dim Arrays und Pointer on Sun, 18 Nov 2007 15:16:29 GMT]]></title><description><![CDATA[<p>Bei jedem durchlauf einfach den Pointer um 1 erhöhen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1405362</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1405362</guid><dc:creator><![CDATA[*D*]]></dc:creator><pubDate>Sun, 18 Nov 2007 15:16:29 GMT</pubDate></item><item><title><![CDATA[Reply to 3-dim Arrays und Pointer on Sun, 18 Nov 2007 16:17:04 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">// Program: threedim_array.C
// iterate over a multidimensional array

#include &lt;iostream&gt;

int main() 
{
  int a[4][2][3] = 
    {              // the 4 elements of a:
      {            // the 2 elements of a[0]:
	{2, 4, 5}, // the three elements of a[0][0]
	{4, 6, 7}  // the three elements of a[0][1]
      }, 
      {            // the 2 elements of a[1]:
	{1, 5, 9}, // the three elements of a[1][0]
	{4, 6, 1}  // the three elements of a[1][1]
      }, 
      {            // the 2 elements of a[2]:
	{5, 9, 0}, // the three elements of a[2][0]
	{1, 5, 3}  // the three elements of a[2][1]
      }, 
      {            // the 2 elements of a[3]:
	{6, 7, 7}, // the three elements of a[3][0]
	{7, 8, 5}  // the three elements of a[3][1]
      } 
    };

  int (*p)[2][3]=a; 

  for (int i=0,j,k; i&lt;4; i++) {
       std::cout&lt;&lt; &quot;\n&quot;;
    for(j=0;j&lt;2;j++) {

      for(k=0;k&lt;3;++k){
	std::cout&lt;&lt; a[i][j][k] &lt;&lt; &quot; &quot;;

	}
     }
   } 

  return 0;

}
</code></pre>
<p>Danke für eure tipps - natürlich macht ihr meine Hausaufgaben nicht, habs ja selber versucht, brauchte einfach ein paar inputs...</p>
<p>Ok, das obige Programm funktioniert und ich kriege den Output:</p>
<p>2 4 5 4 6 7<br />
1 5 9 4 6 1<br />
5 9 0 1 5 3<br />
6 7 7 7 8 5</p>
<p>, was mir gefällt.</p>
<p>Zwei Sachen sind mir jetzt aber noch unklar, hoffe, jemand kann mir das erklären.</p>
<ol>
<li>Habe ich eigentlich in meinem Code die gewünschte Zeigerarithmetik verwendet - mir ist leider immernoch nicht so klar, was das überhaupt wirklich ist, obschon ich nochmals das Skript durchgelesen und mir die Power-Pointpräsentation aus der Vorlesung noch einmal sorgfältig angeschaut habe <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></li>
<li>Der Pointer selbst: Es compiliert ja mit</li>
</ol>
<pre><code class="language-cpp">int (*p)[2][3]=a;
</code></pre>
<p>Ich begreife aber - und das hängt mit 1) zusammen - nicht ganz, wieso der so dastehen muss. Zuerst habe ich versucht: int (*p)[4]=a; Dann kam eine Meldung, dass die Konversion nicht klappt, dann machte ich mal int (*p)[4][2][3]=a; dieselbe Meldung, dann probierte ich einfach mal das obige und das klappte.</p>
<p>Mit grossem Dank im Voraus auf alle Erklärungen,</p>
<p>Damian</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1405402</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1405402</guid><dc:creator><![CDATA[Damian]]></dc:creator><pubDate>Sun, 18 Nov 2007 16:17:04 GMT</pubDate></item><item><title><![CDATA[Reply to 3-dim Arrays und Pointer on Sun, 18 Nov 2007 16:19:44 GMT]]></title><description><![CDATA[<p>Warum schreibst du nicht oben</p>
<pre><code class="language-cpp">using namespace std;
</code></pre>
<p>Damit könntest du dir das std:: sparen!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1405406</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1405406</guid><dc:creator><![CDATA[*D*]]></dc:creator><pubDate>Sun, 18 Nov 2007 16:19:44 GMT</pubDate></item><item><title><![CDATA[Reply to 3-dim Arrays und Pointer on Sun, 18 Nov 2007 16:22:36 GMT]]></title><description><![CDATA[<p>D schrieb:</p>
<blockquote>
<p>Warum schreibst du nicht oben</p>
<pre><code class="language-cpp">using namespace std;
</code></pre>
<p>Damit könntest du dir das std:: sparen!</p>
</blockquote>
<p>Mach es nicht!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1405408</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1405408</guid><dc:creator><![CDATA[ne du noob]]></dc:creator><pubDate>Sun, 18 Nov 2007 16:22:36 GMT</pubDate></item><item><title><![CDATA[Reply to 3-dim Arrays und Pointer on Sun, 18 Nov 2007 16:23:25 GMT]]></title><description><![CDATA[<p>Warum denn nicht?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1405409</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1405409</guid><dc:creator><![CDATA[*D*]]></dc:creator><pubDate>Sun, 18 Nov 2007 16:23:25 GMT</pubDate></item><item><title><![CDATA[Reply to 3-dim Arrays und Pointer on Sun, 18 Nov 2007 16:25:56 GMT]]></title><description><![CDATA[<p>Schau dir einfach mal ein paar alte Threads an. In ca. jedem 20sten steht warum.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1405415</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1405415</guid><dc:creator><![CDATA[PiperAtTheGatesOfDawn]]></dc:creator><pubDate>Sun, 18 Nov 2007 16:25:56 GMT</pubDate></item><item><title><![CDATA[Reply to 3-dim Arrays und Pointer on Sun, 18 Nov 2007 16:27:23 GMT]]></title><description><![CDATA[<p>Bin zu faul zum suchen...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1405416</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1405416</guid><dc:creator><![CDATA[*D*]]></dc:creator><pubDate>Sun, 18 Nov 2007 16:27:23 GMT</pubDate></item><item><title><![CDATA[Reply to 3-dim Arrays und Pointer on Sun, 18 Nov 2007 16:29:08 GMT]]></title><description><![CDATA[<p>Tja dann wirst du auch keine Erklärung bekommen. Aber mal als Anregung: Wofür gibt es Namensräume? Was ist ihr Sinn &amp; Nutzen? ...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1405419</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1405419</guid><dc:creator><![CDATA[*D*Evil]]></dc:creator><pubDate>Sun, 18 Nov 2007 16:29:08 GMT</pubDate></item><item><title><![CDATA[Reply to 3-dim Arrays und Pointer on Sun, 18 Nov 2007 19:05:48 GMT]]></title><description><![CDATA[<p>Halte ich zwar für übertrieben bei so 'nem simplen Beispiel, aber prinzipiell haben die Verfechter des sauberen Codes schon Recht. Benutze also lieber die using-Direktive mit std::cout.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1405530</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1405530</guid><dc:creator><![CDATA[moagnus]]></dc:creator><pubDate>Sun, 18 Nov 2007 19:05:48 GMT</pubDate></item><item><title><![CDATA[Reply to 3-dim Arrays und Pointer on Mon, 19 Nov 2007 21:03:45 GMT]]></title><description><![CDATA[<p>So nach 2 Stunden pröbeln etc. habe ich die Lösung - so glaube ich - gefunden..</p>
<p>wäre froh, wenn jemand bestätigen könnte, dass dies so gemeint war....</p>
<pre><code class="language-cpp">// Program: threedim_array.C
// iterate over a multidimensional array

#include &lt;iostream&gt;

int main()
{
  int a[4][2][3] =
    {              // the 4 elements of a:
      {            // the 2 elements of a[0]:
	{2, 4, 5}, // the three elements of a[0][0]
	{4, 6, 7}  // the three elements of a[0][1]
      },
      {            // the 2 elements of a[1]:
	{1, 5, 9}, // the three elements of a[1][0]
	{4, 6, 1}  // the three elements of a[1][1]
      },
      {            // the 2 elements of a[2]:
	{5, 9, 0}, // the three elements of a[2][0]
	{1, 5, 3}  // the three elements of a[2][1]
      },
      {            // the 2 elements of a[3]:
	{6, 7, 7}, // the three elements of a[3][0]
	{7, 8, 5}  // the three elements of a[3][1]
      }
    };

// Output: The above array using (damn) pointer arithmetic

	// Firstly, we initalize a pointer which points 
         // to the first element of a. (That is a to say)

        int (*p)[2][3] = a;

	// Secondly, we initialize a pointer which points
         // to the first element of the first element of a.
	// In random acces we would talk \1: a[0][0]
	int (*q)[3] = *p;

	// Now it is getting difficult
         // Finally we initialize a pointer of the first element of
         // the element of the element of a.
	// These is equal to the random access' a[0][0][0]

	int (*r) = *q;

  for (int i=0,j,k; i&lt;4; i++) {
    (p)++;  
       for(j=0;j&lt;2;j++) {
        (q)++;  
         for(k=0;k&lt;3;++k){
	std::cout&lt;&lt;  *r &lt;&lt; &quot; &quot;;              // Outputs every number one by one on one line (if only this std::cout is used)
        (r)++;
		}
     }
   }

	return 0;

}
</code></pre>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>Damian</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1406223</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1406223</guid><dc:creator><![CDATA[Damian]]></dc:creator><pubDate>Mon, 19 Nov 2007 21:03:45 GMT</pubDate></item></channel></rss>