<?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[char array als pointer argument]]></title><description><![CDATA[<p>Hallo,</p>
<p>Ich versuche mein char Array als Pointer an eine Funktion weiterzugeben, doch erhalte folgende Fehlermeldung:</p>
<pre><code class="language-cli">cannot convert `char (*)[2][2]' to `char* (*)[2]' for argument `1' to `void test(char* (*)[2])'
</code></pre>
<p>Hier ist mein Code:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
using namespace std;

void test(char* board[2][2]);

int main() {
    char board[2][2] = {{' ', ' '},
                        {' ', ' '}};
    test(&amp;board);

    // Do stuff
}

void test(char* board[2][2]) {
     *board[0][0] = 'X';

     // Do stuff
}
</code></pre>
<p>Achja, ich benutze Dec-C++ als compiler, doch mit Visual Studios erhielt ich etwa den selben Error.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/254455/char-array-als-pointer-argument</link><generator>RSS for Node</generator><lastBuildDate>Thu, 16 Apr 2026 12:01:45 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/254455.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 16 Nov 2009 19:02:54 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to char array als pointer argument on Mon, 16 Nov 2009 19:02:54 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>Ich versuche mein char Array als Pointer an eine Funktion weiterzugeben, doch erhalte folgende Fehlermeldung:</p>
<pre><code class="language-cli">cannot convert `char (*)[2][2]' to `char* (*)[2]' for argument `1' to `void test(char* (*)[2])'
</code></pre>
<p>Hier ist mein Code:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
using namespace std;

void test(char* board[2][2]);

int main() {
    char board[2][2] = {{' ', ' '},
                        {' ', ' '}};
    test(&amp;board);

    // Do stuff
}

void test(char* board[2][2]) {
     *board[0][0] = 'X';

     // Do stuff
}
</code></pre>
<p>Achja, ich benutze Dec-C++ als compiler, doch mit Visual Studios erhielt ich etwa den selben Error.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1808992</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1808992</guid><dc:creator><![CDATA[BraucheHilfe]]></dc:creator><pubDate>Mon, 16 Nov 2009 19:02:54 GMT</pubDate></item><item><title><![CDATA[Reply to char array als pointer argument on Mon, 16 Nov 2009 19:16:19 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;iostream&gt; 
using namespace std; 

void test(char(*board)[2]); 

int main() { 
    char board[2][2] = {{' ', ' '}, 
                        {' ', ' '}}; 
    test(board); 

    // Do stuff 
} 

void test(char(*board)[2]) { 
     board[0][0] = 'X'; 

     // Do stuff 
}
</code></pre>
<p><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/1809001</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1809001</guid><dc:creator><![CDATA[XXL]]></dc:creator><pubDate>Mon, 16 Nov 2009 19:16:19 GMT</pubDate></item><item><title><![CDATA[Reply to char array als pointer argument on Mon, 16 Nov 2009 19:19:00 GMT]]></title><description><![CDATA[<p>Klappt nun, danke!</p>
<p>Aber könnteste mir das bitte erklären?<br />
Hab keinen Plan warum du das so machst :p</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1809006</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1809006</guid><dc:creator><![CDATA[BraucheHilfe]]></dc:creator><pubDate>Mon, 16 Nov 2009 19:19:00 GMT</pubDate></item><item><title><![CDATA[Reply to char array als pointer argument on Mon, 16 Nov 2009 19:42:03 GMT]]></title><description><![CDATA[<p>BraucheHilfe schrieb:</p>
<blockquote>
<p>Klappt nun, danke!</p>
<p>Aber könnteste mir das bitte erklären?<br />
Hab keinen Plan warum du das so machst :p</p>
</blockquote>
<p>Lese mal nach, wie man Zeiger auf mehrdimensionale Arrays deklariert!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1809020</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1809020</guid><dc:creator><![CDATA[XXL]]></dc:creator><pubDate>Mon, 16 Nov 2009 19:42:03 GMT</pubDate></item><item><title><![CDATA[Reply to char array als pointer argument on Mon, 16 Nov 2009 20:04:47 GMT]]></title><description><![CDATA[<p>BraucheHilfe schrieb:</p>
<blockquote>
<p>Ich versuche mein char Array als Pointer an eine Funktion weiterzugeben, doch erhalte folgende Fehlermeldung:</p>
<pre><code class="language-cli">cannot convert `char (*)[2][2]' to `char* (*)[2]' for argument `1' to `void test(char* (*)[2])'
</code></pre>
<p>Hier ist mein Code:</p>
<pre><code class="language-cpp">void test(char* board[2][2]);

int main() {
    char board[2][2] = {{' ', ' '},
                        {' ', ' '}};
    test(&amp;board);
}
</code></pre>
</blockquote>
<p>Der Subscript-Operator hat eine höhere Präzedenz als das unäre *.</p>
<pre><code>char *board [2][2]   &lt;-- hast Du geschrieben
char(*board)[2][2]   &lt;-- wolltest Du haben
</code></pre>
<p>Das erste ist ein Array von Array von Zeigern auf char.<br />
Das zweite ist ein Zeiger auf ein Array von Array von char.</p>
<p>Außerdem wird der Typ in der Parameterdeklaration noch angepasst. Handelt es sich auf der obersten Ebene um ein Array, wird einfach ein Zeiger draus gemacht. Deswegen hat der Compiler in der Fehlermeldung aus</p>
<pre><code>char*board[2][2]  ---&gt;  char*(*board)[2]
</code></pre>
<p>gemacht.</p>
<p>Deine test-Funktion hättest Du dann aber auch ändern müssen. Du hast ja einen Zeiger auf das &quot;ArrayArray&quot; übergeben.</p>
<pre><code class="language-cpp">void test(char (*p)[2][2]) {
  p[0][0] = 'x'; // FALSCH
  (*p)[0][0] = 'x'; // RIGHTIG
}
</code></pre>
<p>Alternative 1 (Referenz statt Zeiger)</p>
<pre><code class="language-cpp">void test(char (&amp;arr)[2][2]) {
  arr[0][0] = 'x';
}

int main() {
  char arr[2][2];
  test(arr);
}
</code></pre>
<p>Alternative 2 (Array-to-Pointer-Decay)</p>
<pre><code class="language-cpp">void test(char (*p)[2]) { // äquivalent zu char p[][2]
  p[0][0] = 'x';
}

int main() {
  char arr[2][2];
  test(arr); // übergibt einen Zeiger auf das erste Element vom Typ char[2]
}
</code></pre>
<p>Gruß,<br />
SP</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1809037</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1809037</guid><dc:creator><![CDATA[Sebastian Pizer]]></dc:creator><pubDate>Mon, 16 Nov 2009 20:04:47 GMT</pubDate></item><item><title><![CDATA[Reply to char array als pointer argument on Mon, 16 Nov 2009 22:35:07 GMT]]></title><description><![CDATA[<p>Hier gibts eine <a href="http://magazin.c-plusplus.net/artikel/Pointer%20in%20C%28PlusPlus%29" rel="nofollow">gute Einführung</a> in die Programmierung mit Zeigern in C++.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1809093</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1809093</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Mon, 16 Nov 2009 22:35:07 GMT</pubDate></item></channel></rss>