<?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[Frage zu Array int[x,x];]]></title><description><![CDATA[<p>Ich hab hier irgendwo eben im Forum diesen Code entdeckt.^^</p>
<pre><code class="language-cpp">int* foobar = new int[2,4];
foobar[0,2] = 5;
foobar[1,2] = 10;
cout &lt;&lt; foobar[1,2];
delete [] foobar;
</code></pre>
<p>Ich kenne wohl sowas wie z.b.: int *[2][4];</p>
<p>Aber sowas wie oben habe ich noch nicht gesehen was bedeutet denn die 2,4?<br />
Werden da 2,4 Elemente erstellt? ... Wohl er nicht. Kann mir jemand erklären was das ist?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/307495/frage-zu-array-int-x-x</link><generator>RSS for Node</generator><lastBuildDate>Thu, 06 Aug 2026 18:02:15 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/307495.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 28 Aug 2012 12:55:56 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Frage zu Array int[x,x]; on Tue, 28 Aug 2012 12:55:56 GMT]]></title><description><![CDATA[<p>Ich hab hier irgendwo eben im Forum diesen Code entdeckt.^^</p>
<pre><code class="language-cpp">int* foobar = new int[2,4];
foobar[0,2] = 5;
foobar[1,2] = 10;
cout &lt;&lt; foobar[1,2];
delete [] foobar;
</code></pre>
<p>Ich kenne wohl sowas wie z.b.: int *[2][4];</p>
<p>Aber sowas wie oben habe ich noch nicht gesehen was bedeutet denn die 2,4?<br />
Werden da 2,4 Elemente erstellt? ... Wohl er nicht. Kann mir jemand erklären was das ist?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2246296</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2246296</guid><dc:creator><![CDATA[arrAy_]]></dc:creator><pubDate>Tue, 28 Aug 2012 12:55:56 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu Array int[x,x]; on Tue, 28 Aug 2012 13:02:20 GMT]]></title><description><![CDATA[<p><code>2,4</code> ist <code>4</code> . Nicht jeder Code hier im Forum ist richtig. Guck immer, von wem er stammt oder was der Autor damit ausdrücken wollte. Lies diesen Beitrag (aus dem du das wohl hast) mal vollständig und aufmerksam:<br />
<a href="http://www.c-plusplus.net/forum/p2245931#2245931" rel="nofollow">http://www.c-plusplus.net/forum/p2245931#2245931</a><br />
Der Autor (Michael E.) wollte nämlich an einem vereinfachten Beispiel erklären, was für ein Unsinn diese Art von Code ist.</p>
<p>edit: Falls dir der Hintergrund zu der hier benutzten Syntax fehlt:<br />
<a href="http://en.wikipedia.org/wiki/Comma_operator" rel="nofollow">http://en.wikipedia.org/wiki/Comma_operator</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2246300</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2246300</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Tue, 28 Aug 2012 13:02:20 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu Array int[x,x]; on Tue, 28 Aug 2012 13:01:45 GMT]]></title><description><![CDATA[<p>n3337 schrieb:</p>
<blockquote>
<p>5.18 Comma operator [expr.comma]<br />
1 The comma operator groups left-to-right.<br />
expression:<br />
assignment-expression<br />
expression , assignment-expression</p>
<p>A pair of expressions separated by a comma is evaluated left-to-right; the left expression is a discarded-value expression (Clause 5).83 Every value computation and side effect associated with the left expression is sequenced before every value computation and side effect associated with the right expression. The type and value of the result are the type and value of the right operand; the result is of the same value category as its right operand, and is a bit-field if its right operand<br />
is a glvalue and a bit-field.</p>
<p>2 In contexts where comma is given a special meaning, [ Example: in lists of arguments to functions (5.2.2) and lists of initializers (8.5) — end example ] the comma operator as described in Clause 5 can appear only in parentheses. [ Example:</p>
<p>f(a, (t=3, t+2), c);</p>
<p>has three arguments, the second of which has the value 5. — end example ]</p>
</blockquote>
<p>Der Ausdruck</p>
<pre><code class="language-cpp">2,4
</code></pre>
<p>hat den Wert 4, der Teilausdruck 2 hat den Wert 2, dieser Wert wird aber verworfen; da der Ausdruck 2 keine Seiteneffekte hat, bewirkt er absolut nichts.</p>
<pre><code class="language-cpp">int* foobar = new int[2,4];
</code></pre>
<p>und</p>
<pre><code class="language-cpp">int* foobar = new int[4];
</code></pre>
<p>haben exakt den gleichen Effekt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2246302</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2246302</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Tue, 28 Aug 2012 13:01:45 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu Array int[x,x]; on Tue, 28 Aug 2012 14:20:09 GMT]]></title><description><![CDATA[<p>Der Code Auszug vom Initialen Post stammt von hier (1. Post von Michael E.):<br />
<a href="http://www.c-plusplus.net/forum/307452" rel="nofollow">http://www.c-plusplus.net/forum/307452</a></p>
<p>Nur wegen der Vollständigkeit...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2246326</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2246326</guid><dc:creator><![CDATA[theta]]></dc:creator><pubDate>Tue, 28 Aug 2012 14:20:09 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu Array int[x,x]; on Tue, 28 Aug 2012 14:36:46 GMT]]></title><description><![CDATA[<p>Das geht doch super:</p>
<pre><code class="language-cpp">int main()
{
  twodarr&lt;int&gt; a(2, 5);
  a[O, 2] = 3;
  a[O, 4] = 10;
  for (int i = 0; i &lt; 5; ++i)
    std::cout &lt;&lt; a[O, i] &lt;&lt; ' ';
  std::cout &lt;&lt; &quot;\b\n&quot;;
}
</code></pre>
<p>Man muss sich halt das Array selber schreiben.</p>
<pre><code class="language-cpp">enum index_e { O=0, I, II, III };
struct index_proxy { int y, x; index_proxy(int y, int x) : y(y), x(x) {} };

index_proxy operator,(index_e y, int x)
{
  return index_proxy(static_cast&lt;int&gt;(y), x);
}

template &lt;typename T&gt;
class twodarr {
  std::vector&lt;T&gt; data;
  int w;
public:
  typedef T type;
  twodarr(int h, int w) : data(w*h), w(w) {}

  type&amp; operator[](index_proxy pos)
  { return data[w*pos.y + pos.x]; }
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2246334</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2246334</guid><dc:creator><![CDATA[supskribor]]></dc:creator><pubDate>Tue, 28 Aug 2012 14:36:46 GMT</pubDate></item></channel></rss>