<?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[Anfaengerfrage]]></title><description><![CDATA[<p>Hi, zwei kleine Fragen:<br />
1. Warum wird shit2 beim compilen angezeigt?<br />
2. Warum kann ich shit2 nicht mit 3 Variablen füllen?</p>
<p>Danke!</p>
<pre><code>#include &lt;iostream&gt;

using namespace std;

int main () {

	char shit2[3] = &quot;ba&quot;;
    char shit[3];
    shit[0] = 'a';
    shit[1] = 'b';
    shit[2] = 'c';

	cout &lt;&lt; &quot;Shit ohne Aenderung: &quot; &lt;&lt; endl &lt;&lt; shit &lt;&lt; endl;

	cout &lt;&lt; &quot;Shit mit Aenderung: :&quot; &lt;&lt; endl &lt;&lt; shit &lt;&lt; endl;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/320913/anfaengerfrage</link><generator>RSS for Node</generator><lastBuildDate>Wed, 22 Jul 2026 13:14:02 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/320913.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 16 Oct 2013 21:07:34 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Anfaengerfrage on Wed, 16 Oct 2013 21:07:34 GMT]]></title><description><![CDATA[<p>Hi, zwei kleine Fragen:<br />
1. Warum wird shit2 beim compilen angezeigt?<br />
2. Warum kann ich shit2 nicht mit 3 Variablen füllen?</p>
<p>Danke!</p>
<pre><code>#include &lt;iostream&gt;

using namespace std;

int main () {

	char shit2[3] = &quot;ba&quot;;
    char shit[3];
    shit[0] = 'a';
    shit[1] = 'b';
    shit[2] = 'c';

	cout &lt;&lt; &quot;Shit ohne Aenderung: &quot; &lt;&lt; endl &lt;&lt; shit &lt;&lt; endl;

	cout &lt;&lt; &quot;Shit mit Aenderung: :&quot; &lt;&lt; endl &lt;&lt; shit &lt;&lt; endl;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2360794</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2360794</guid><dc:creator><![CDATA[kamelkacke]]></dc:creator><pubDate>Wed, 16 Oct 2013 21:07:34 GMT</pubDate></item><item><title><![CDATA[Reply to Anfaengerfrage on Wed, 16 Oct 2013 21:46:47 GMT]]></title><description><![CDATA[<blockquote>
<p>1. Warum wird shit2 beim compilen angezeigt?</p>
</blockquote>
<p>Du meinst wohl, Intellisense wittert einen Fehler. Nun, da hab ich keine Ahnung, obiger Code sieht völlig in Ordnung aus.</p>
<blockquote>
<p>2. Warum kann ich shit2 nicht mit 3 Variablen füllen?</p>
</blockquote>
<p>Kannst du, und tust du.</p>
<p>Wenn du ein char-Array mit einem String-Literal initialisierst, dann füllst du die ersten Zeichen mit den Zeichen aus dem Literal, aber das letzte Zeichen ist immer das Nullzeichen. Daher brauchst du in einem char-Array mindestens immer Platz für das Nullzeichen.</p>
<p>Das heißt, das letzte Element deines Arrays ist nach einer solchen Initialisierung immer 0 und kann nicht für andere Zeichen verwendet werden, denn sonst ist das Array nicht nullterminiert (und das ist eine Grundvoraussetzung für viele Funktionen die einen C-String nehmen!).</p>
<pre><code>/// sizeof angewandt auf ein String-Literal gibt die Anzahl der Zeichen wieder:
std::cout &lt;&lt; sizeof(&quot;HA!&quot;); // Nanu, das gibt ja Vier aus?!
</code></pre>
<p>Merke: Ein String-Literal &quot;a<sub>1</sub>a<sub>2</sub>..a<sub>n</sub>&quot; führt zu einem Array mit Inhalt {'a<sub>1</sub>', 'a<sub>2</sub>', ...., 'a<sub>n</sub>', '\0'}.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2360798</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2360798</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Wed, 16 Oct 2013 21:46:47 GMT</pubDate></item><item><title><![CDATA[Reply to Anfaengerfrage on Wed, 16 Oct 2013 22:16:35 GMT]]></title><description><![CDATA[<p>Vielen Dank fuer deine Antwort!</p>
<p>Nagut dann hat mein handycompiler wohl das erste mal hardcore abgefloppt, schade : (</p>
<p>Wenn ich shit2 mit 3 werten fuellen will, sagt die fehlermeld, das der string zu lang ist, und wenn ich dann 2 werte eingebe und starte kommt nach der ausgabe von shit, noch in der selben zeile irgendein merkwuerdiges zeichen und dann shit2, obwohl ich shit2 zur ausgabe ja nicht eingetragen habe.</p>
<p>Danke nochmal!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2360802</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2360802</guid><dc:creator><![CDATA[kamelkacke]]></dc:creator><pubDate>Wed, 16 Oct 2013 22:16:35 GMT</pubDate></item><item><title><![CDATA[Reply to Anfaengerfrage on Wed, 16 Oct 2013 22:22:50 GMT]]></title><description><![CDATA[<p>kopier mal die Fehlermeld hier rein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2360803</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2360803</guid><dc:creator><![CDATA[out]]></dc:creator><pubDate>Wed, 16 Oct 2013 22:22:50 GMT</pubDate></item><item><title><![CDATA[Reply to Anfaengerfrage on Wed, 16 Oct 2013 22:27:01 GMT]]></title><description><![CDATA[<p>/data/data/com.n0n3m4.droidc/files/temp.c: In function 'int main()':<br />
/data/data/com.n0n3m4.droidc/files/temp.c:7:18: error: initializer-string for array of chars is too long [-fpermissive]<br />
char bitch[3] = &quot;xbc&quot;;<br />
^<br />
compilation terminated due to -Wfatal-errors.</p>
<p>Hab die variable in der zwischenzeit aus testzwecken unbenannt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2360805</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2360805</guid><dc:creator><![CDATA[kamelkacke]]></dc:creator><pubDate>Wed, 16 Oct 2013 22:27:01 GMT</pubDate></item><item><title><![CDATA[Reply to Anfaengerfrage on Thu, 17 Oct 2013 03:44:53 GMT]]></title><description><![CDATA[<p>Du darfst die Antwort von Arcoth schon ruhig lesen. Da steht fast alles drin, was du wissen willst.</p>
<p>Ums vielleicht klarer zu machen:</p>
<pre><code>char bitch[3] = &quot;xbc&quot;;
</code></pre>
<p>ist im Grunde (keine Korinthenkackerei von den üblichen Verdächtigen bitte) das selbe wie</p>
<pre><code>char bitch[3];
bitch[0] = 'x';
bitch[1] = 'b';
bitch[2] = 'c';
bitch[3] = '\0';
</code></pre>
<p>Das sind nunmal vier Zeichen, und wie Arcoth gesagt hat brauchen viele Funktionen das eben, um richtig zu funktionieren. Deshalb kommt auch bei deiner Ausgabe von &quot;shit&quot; danach blödsinn raus, weil du das \0 eben nicht drinnen hast.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2360813</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2360813</guid><dc:creator><![CDATA[kleiner Troll]]></dc:creator><pubDate>Thu, 17 Oct 2013 03:44:53 GMT</pubDate></item><item><title><![CDATA[Reply to Anfaengerfrage on Thu, 17 Oct 2013 13:50:21 GMT]]></title><description><![CDATA[<p>Also manchmal funktionieren 3 zeichen und manchmal nicht?</p>
<p>Ich mein ich kenne die null termination, aber wie du geschrieben hast, stehen in dem array 4 plaetze zur verfuegung. Also müssten ja 3 buchstaben und eine null terminierung reinpassen. Ich habs grad mit int versucht und es klappt..</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2360908</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2360908</guid><dc:creator><![CDATA[kamelkacke]]></dc:creator><pubDate>Thu, 17 Oct 2013 13:50:21 GMT</pubDate></item><item><title><![CDATA[Reply to Anfaengerfrage on Thu, 17 Oct 2013 13:55:57 GMT]]></title><description><![CDATA[<p>kamelkacke schrieb:</p>
<blockquote>
<p>Also manchmal funktionieren 3 zeichen und manchmal nicht?</p>
<p>Ich mein ich kenne die null termination, aber wie du geschrieben hast, stehen in dem array 4 plaetze zur verfuegung. Also müssten ja 3 buchstaben und eine null terminierung reinpassen. Ich habs grad mit int versucht und es klappt..</p>
</blockquote>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /> Das einzige was ein Terminierungszeichen hat, ist ein <code>&quot;xyz&quot;</code> , also ein Zeichenkettenliteral. Keine Zeichen in Anführungszeichen = Keine Nullterminierung. Die Nullterminierung ist auch nur dafür da, dass die Funktionen, die mit deinem String arbeiten, wissen, wann der String zu Ende ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2360911</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2360911</guid><dc:creator><![CDATA[out]]></dc:creator><pubDate>Thu, 17 Oct 2013 13:55:57 GMT</pubDate></item><item><title><![CDATA[Reply to Anfaengerfrage on Thu, 17 Oct 2013 14:10:57 GMT]]></title><description><![CDATA[<p>std::string</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2360912</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2360912</guid><dc:creator><![CDATA[dr. dipl. prof. troll]]></dc:creator><pubDate>Thu, 17 Oct 2013 14:10:57 GMT</pubDate></item><item><title><![CDATA[Reply to Anfaengerfrage on Thu, 17 Oct 2013 14:39:09 GMT]]></title><description><![CDATA[<p>Also bei einer string definition eines arrays gehen jeweils 2 plaetze fuer die &quot;&quot; floeten und bei einzelner definition geht ein platz weg wegen der nullterminierung?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2360918</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2360918</guid><dc:creator><![CDATA[kamelkacke]]></dc:creator><pubDate>Thu, 17 Oct 2013 14:39:09 GMT</pubDate></item><item><title><![CDATA[Reply to Anfaengerfrage on Thu, 17 Oct 2013 14:46:36 GMT]]></title><description><![CDATA[<p>kamelkacke schrieb:</p>
<blockquote>
<p>.., aber wie du geschrieben hast, stehen in dem array 4 plaetze zur verfuegung. ...</p>
</blockquote>
<p>Nein, da sind nur 3 Plätze.<br />
<code>char bitch[3];</code> bedeutet: Ein char-Array mit <strong>drei</strong> Elementen, dessen Index von 0 bis 2 geht. Da gibt es kein <code>bitch[3]</code> zum Zeichen ablegen.</p>
<p>Die &quot;&quot; von einem Stringliteral werden nicht im Array abgelegt. Das einzige was dazu kommt ist der '\0'-Terminator.</p>
<p>Und du darfst C-Strings nicht mit einem Zeichen verwechseln.<br />
&quot;9&quot; ist etwas anderes als '9' ist etwas anderes als 9</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2360921</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2360921</guid><dc:creator><![CDATA[DirkB]]></dc:creator><pubDate>Thu, 17 Oct 2013 14:46:36 GMT</pubDate></item><item><title><![CDATA[Reply to Anfaengerfrage on Thu, 17 Oct 2013 14:55:26 GMT]]></title><description><![CDATA[<p>&quot;xyz&quot; ist vom Typ const char [4]. Der Inhalt ist {'x', 'y', 'z', '\0'}. Wenn du schreibst const char bla[3] = &quot;xyz&quot;;, dann ist bla vom Typ const char [3] mit dem Inhalt {'x', 'y', 'z'}.</p>
<p>cout ist ein Objekt was ungefähr so funktioniert:</p>
<pre><code>ostream &amp;operator &lt;&lt; (const char *s){
    while (*s != '\0'){
        gebeAus(*s);
        s++;
    }
    return *this;
}
</code></pre>
<p>Er gibt so lange die Zeichen aus bis er ein '\0'-Zeichen trifft. Da dein Array nicht mit einem '\0'-Zeichen endet gibt cout munter weiter irgendwelchen Speicher aus bis er zufällig eine '\0' findet oder das Betriebssystem dein Programm wegen einer Zugriffsverletzung abschießt.<br />
Lösung: Das '\0'-Zeichen dran tun oder std::string benutzen oder cout sonst irgendwie sagen, dass er nur die ersten 3 Zeichen ausgeben soll oder sich freuen, dass komische Sachen ausgegeben werden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2360924</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2360924</guid><dc:creator><![CDATA[nwp3]]></dc:creator><pubDate>Thu, 17 Oct 2013 14:55:26 GMT</pubDate></item><item><title><![CDATA[Reply to Anfaengerfrage on Thu, 17 Oct 2013 15:13:12 GMT]]></title><description><![CDATA[<p>nwp3 schrieb:</p>
<blockquote>
<p>Wenn du schreibst const char bla[3] = &quot;xyz&quot;;, dann ist bla vom Typ const char [3] mit dem Inhalt {'x', 'y', 'z'}.</p>
</blockquote>
<p>Das sollte ill-formed sein. Ein Zeichenkettenliteral endet immer mit einem 0-Terminator, und damit liegen zuviele Initialisierer vor.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2360929</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2360929</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Thu, 17 Oct 2013 15:13:12 GMT</pubDate></item><item><title><![CDATA[Reply to Anfaengerfrage on Thu, 17 Oct 2013 15:32:25 GMT]]></title><description><![CDATA[<p>Boah...also der compiler macht alles richtig, indem er in bitch keine 3 buchstaben aufnehmen will??</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2360936</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2360936</guid><dc:creator><![CDATA[kamelkacke]]></dc:creator><pubDate>Thu, 17 Oct 2013 15:32:25 GMT</pubDate></item><item><title><![CDATA[Reply to Anfaengerfrage on Thu, 17 Oct 2013 15:41:09 GMT]]></title><description><![CDATA[<p>vier</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2360938</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2360938</guid><dc:creator><![CDATA[ScottZhang]]></dc:creator><pubDate>Thu, 17 Oct 2013 15:41:09 GMT</pubDate></item><item><title><![CDATA[Reply to Anfaengerfrage on Thu, 17 Oct 2013 15:44:40 GMT]]></title><description><![CDATA[<p>Er nimmt aber nicht mal drei, darum gehts doch.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2360939</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2360939</guid><dc:creator><![CDATA[kamelkacke]]></dc:creator><pubDate>Thu, 17 Oct 2013 15:44:40 GMT</pubDate></item><item><title><![CDATA[Reply to Anfaengerfrage on Thu, 17 Oct 2013 15:56:57 GMT]]></title><description><![CDATA[<p>Doch, da passen drei Zeichen rein. Wenn das letzte Zeichen kein '\0' ist, kannst du es aber nicht mit <code>cout</code> überprüfen, da das bei einem char* einen C-String erwartet.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2360942</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2360942</guid><dc:creator><![CDATA[DirkB]]></dc:creator><pubDate>Thu, 17 Oct 2013 15:56:57 GMT</pubDate></item><item><title><![CDATA[Reply to Anfaengerfrage on Thu, 17 Oct 2013 15:57:53 GMT]]></title><description><![CDATA[<p>Er nimmt noch nichtmal einen, er nimmt garkeinen, weil er die vier nicht nimmt, weil vier nicht in drei passen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2360944</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2360944</guid><dc:creator><![CDATA[ScottZhang]]></dc:creator><pubDate>Thu, 17 Oct 2013 15:57:53 GMT</pubDate></item><item><title><![CDATA[Reply to Anfaengerfrage on Thu, 17 Oct 2013 16:48:13 GMT]]></title><description><![CDATA[<p>Ne guck doch mal auf die compilerwarnung in seite 1. Da steht doch dass 3 fuer ihn zu lang ist</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2360952</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2360952</guid><dc:creator><![CDATA[kamelkacke]]></dc:creator><pubDate>Thu, 17 Oct 2013 16:48:13 GMT</pubDate></item><item><title><![CDATA[Reply to Anfaengerfrage on Thu, 17 Oct 2013 16:58:29 GMT]]></title><description><![CDATA[<p>Nee, steht da nicht!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2360956</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2360956</guid><dc:creator><![CDATA[ScottZhang]]></dc:creator><pubDate>Thu, 17 Oct 2013 16:58:29 GMT</pubDate></item><item><title><![CDATA[Reply to Anfaengerfrage on Thu, 17 Oct 2013 17:21:26 GMT]]></title><description><![CDATA[<p>Don't feed the troll.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2360962</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2360962</guid><dc:creator><![CDATA[Caligulaminus]]></dc:creator><pubDate>Thu, 17 Oct 2013 17:21:26 GMT</pubDate></item><item><title><![CDATA[Reply to Anfaengerfrage on Thu, 17 Oct 2013 18:04:45 GMT]]></title><description><![CDATA[<p>Ok jetzt hab ichs..danke</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2360971</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2360971</guid><dc:creator><![CDATA[kamelkacke]]></dc:creator><pubDate>Thu, 17 Oct 2013 18:04:45 GMT</pubDate></item></channel></rss>