<?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[Verständnisproblem if-Abfragen-Bedingungen]]></title><description><![CDATA[<p>Hi,</p>
<p>ich hab wiedermal ein Verständnisproblem: Für zwei Übungsbeispielen welche if-Abfrageb behandeln liegen für mich vollkommen unverständliche Ergebnisse vor.</p>
<pre><code>int a = 1, b = 2, c = 0;

if (a == b == c)
if (a == b)
cout &lt;&lt; &quot;A&quot; &lt;&lt; a;
else
cout &lt;&lt; &quot;B&quot; &lt;&lt; b;

else
if (b == c)
cout &lt;&lt; &quot;C&quot; &lt;&lt; c;
else
cout &lt;&lt; &quot;HOPPLA&quot;;

cout &lt;&lt; a &lt;&lt; b &lt;&lt; c;
</code></pre>
<p>Hier ist das Ergebnis: B2120<br />
Für mich wäre allerdings: HOPPLA120 logisch da a, b, und c ja eben nicht a==b==c sind <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="😕"
    /></p>
<pre><code>int a = 0, b = 0, c = 0;
if (a == b == c)
if (a == b)
cout &lt;&lt; &quot;A&quot; &lt;&lt; a;
else
cout &lt;&lt; &quot;B&quot; &lt;&lt; b;
else
if (b == c)
cout &lt;&lt; &quot;C&quot; &lt;&lt; c;
else
cout &lt;&lt; &quot;HOPPLA&quot;;

cout &lt;&lt; a &lt;&lt; b &lt;&lt; c;
</code></pre>
<p>Hier ist die Lösung C0000, für mich wäre aber A0000 richtig... wo hab ich meinen Denkfehler? <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="😞"
    /></p>
<p>Cheers,<br />
Flügelnuss</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/328826/verständnisproblem-if-abfragen-bedingungen</link><generator>RSS for Node</generator><lastBuildDate>Tue, 07 Jul 2026 07:39:38 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/328826.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 28 Oct 2014 13:43:48 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Verständnisproblem if-Abfragen-Bedingungen on Tue, 28 Oct 2014 15:28:29 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>ich hab wiedermal ein Verständnisproblem: Für zwei Übungsbeispielen welche if-Abfrageb behandeln liegen für mich vollkommen unverständliche Ergebnisse vor.</p>
<pre><code>int a = 1, b = 2, c = 0;

if (a == b == c)
if (a == b)
cout &lt;&lt; &quot;A&quot; &lt;&lt; a;
else
cout &lt;&lt; &quot;B&quot; &lt;&lt; b;

else
if (b == c)
cout &lt;&lt; &quot;C&quot; &lt;&lt; c;
else
cout &lt;&lt; &quot;HOPPLA&quot;;

cout &lt;&lt; a &lt;&lt; b &lt;&lt; c;
</code></pre>
<p>Hier ist das Ergebnis: B2120<br />
Für mich wäre allerdings: HOPPLA120 logisch da a, b, und c ja eben nicht a==b==c sind <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="😕"
    /></p>
<pre><code>int a = 0, b = 0, c = 0;
if (a == b == c)
if (a == b)
cout &lt;&lt; &quot;A&quot; &lt;&lt; a;
else
cout &lt;&lt; &quot;B&quot; &lt;&lt; b;
else
if (b == c)
cout &lt;&lt; &quot;C&quot; &lt;&lt; c;
else
cout &lt;&lt; &quot;HOPPLA&quot;;

cout &lt;&lt; a &lt;&lt; b &lt;&lt; c;
</code></pre>
<p>Hier ist die Lösung C0000, für mich wäre aber A0000 richtig... wo hab ich meinen Denkfehler? <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="😞"
    /></p>
<p>Cheers,<br />
Flügelnuss</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2424526</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2424526</guid><dc:creator><![CDATA[flügelnuss]]></dc:creator><pubDate>Tue, 28 Oct 2014 15:28:29 GMT</pubDate></item><item><title><![CDATA[Reply to Verständnisproblem if-Abfragen-Bedingungen on Tue, 28 Oct 2014 13:49:23 GMT]]></title><description><![CDATA[<p><a href="http://if-schleife.de/" rel="nofollow">http://if-schleife.de/</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2424527</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2424527</guid><dc:creator><![CDATA[tntnet]]></dc:creator><pubDate>Tue, 28 Oct 2014 13:49:23 GMT</pubDate></item><item><title><![CDATA[Reply to Verständnisproblem if-Abfragen-Bedingungen on Tue, 28 Oct 2014 13:52:44 GMT]]></title><description><![CDATA[<p>Tipp: Was genau bedeutet a==b? Das heißt, welchen Datentyp hat das Ergebnis und welchen Wert unter welchen Bedingungen? Was genau bedeutet a==b==c?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2424529</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2424529</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Tue, 28 Oct 2014 13:52:44 GMT</pubDate></item><item><title><![CDATA[Reply to Verständnisproblem if-Abfragen-Bedingungen on Tue, 28 Oct 2014 13:59:35 GMT]]></title><description><![CDATA[<pre><code>int a = 0, b = 0, c = 0;

if (a == b == c)
{
  if (a == b)
  {
   cout &lt;&lt; &quot;A&quot; &lt;&lt; a;
  }else
  {
  cout &lt;&lt; &quot;B&quot; &lt;&lt; b;
  }else
  {
  if (b == c)
  cout &lt;&lt; &quot;C&quot; &lt;&lt; c;
  }else
  {
  cout &lt;&lt; &quot;HOPPLA&quot;;
  }
  cout &lt;&lt; a &lt;&lt; b &lt;&lt; c;
</code></pre>
<p>eig müsste &quot;AC000&quot; rauskommen wenn ich das richtig sehe... aber ich kann das nicht einschätzen mir fehlen da die klammern...!!</p>
<p>aber egal... wenn &quot;C&quot; da ist und &quot;A&quot; da sein sollte dann schau was das verursacht und wo dein fehler sein könnte...<br />
ich kann deinen code nicht wirklich nachvollziehen ... habe gerade keine ide zurhand... sind die klammern bei mir so richtig gesetzt? wie du es meintest?</p>
<p>falls ja dann kannst du die 2. &quot;if&quot; abfrage wegmachen , entweder machst du 3 ifs ... ist am besten leserlich oder du nutzt else if... 2mal...<br />
-&gt; dann kann man den code besser lesen und du hast nicht solche komischen fehler...<br />
die ifabfragen sind auch sehr verschachtelt...</p>
<p>vll in etwa so:</p>
<pre><code>int a=0;
int b=0;
int c=0;

if(a==b==c)
{

 if(a==b)
 {
  cout &lt;&lt; &quot;A&quot; &lt;&lt; a;
 }

 if(b==c)
 {
  ....
 }

}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2424531</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2424531</guid><dc:creator><![CDATA[NAJA]]></dc:creator><pubDate>Tue, 28 Oct 2014 13:59:35 GMT</pubDate></item><item><title><![CDATA[Reply to Verständnisproblem if-Abfragen-Bedingungen on Tue, 28 Oct 2014 14:01:53 GMT]]></title><description><![CDATA[<p>ps. was ich damit meine ist wenn du deinen code leserlicher anordnest siesht du den fehler alleine <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="😉"
    /> , außer du kennst die funktion von if-abfragen nicht richtig <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /> ....</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2424533</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2424533</guid><dc:creator><![CDATA[NAJA]]></dc:creator><pubDate>Tue, 28 Oct 2014 14:01:53 GMT</pubDate></item><item><title><![CDATA[Reply to Verständnisproblem if-Abfragen-Bedingungen on Tue, 28 Oct 2014 14:10:20 GMT]]></title><description><![CDATA[<p>a == b == c<br />
ist<br />
( a == b ) == c<br />
und macht wahrscheinlich nicht das, was beabsichtigt ist.</p>
<p>Da c int ist, wird das Ergebnis von a == b für den Vergleich mit c in ein int konvertiert (false=&gt;0, true=&gt;1).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2424534</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2424534</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Tue, 28 Oct 2014 14:10:20 GMT</pubDate></item><item><title><![CDATA[Reply to Verständnisproblem if-Abfragen-Bedingungen on Tue, 28 Oct 2014 15:25:44 GMT]]></title><description><![CDATA[<p>@NAJA den Code hab nicht ich geschrieben, ich sollte lediglich den output herausfinden.</p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/904">@bashar</a> &amp; <a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/6642">@camper</a>: Nunja hier ist mein Problem, ich weiß nicht was a==b==c macht. Ich hatte angenommen das ist ein Vergleich aber ich schätze mal das stimmt nicht?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2424541</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2424541</guid><dc:creator><![CDATA[flügelnuss]]></dc:creator><pubDate>Tue, 28 Oct 2014 15:25:44 GMT</pubDate></item><item><title><![CDATA[Reply to Verständnisproblem if-Abfragen-Bedingungen on Tue, 28 Oct 2014 15:29:12 GMT]]></title><description><![CDATA[<p>flügelnuss schrieb:</p>
<blockquote>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/904">@bashar</a> &amp; <a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/6642">@camper</a>: Nunja hier ist mein Problem, ich weiß nicht was a==b==c macht.</p>
</blockquote>
<p>Wie könnte man das herausfinden?</p>
<p>(Eigentlich hat camper die Frage schon beantwortet.)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2424542</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2424542</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Tue, 28 Oct 2014 15:29:12 GMT</pubDate></item><item><title><![CDATA[Reply to Verständnisproblem if-Abfragen-Bedingungen on Tue, 28 Oct 2014 16:27:19 GMT]]></title><description><![CDATA[<blockquote>
<p>(Eigentlich hat camper die Frage schon beantwortet.)</p>
</blockquote>
<p>Nicht nur eigentlich^^</p>
<p>1tes Beispiel:<br />
a = 1, b = 2, c = 0<br />
Für:<br />
a == b == c<br />
-&gt; (a == b) == c</p>
<p>Also: 1 == 2 -&gt; False -&gt; 0<br />
0 == c<br />
-&gt; 0 == 0 -&gt; True -&gt; 1</p>
<p>D.h. die erste if-Bedingung trifft zu.</p>
<p>Da a == b -&gt; 1 == 2 -&gt; falsch ist, trifft das else zu, die Lösung fängt also mit &quot;B&quot; an.</p>
<p>Nach genau dem gleichen Schema wird auch das zweite Beispiel (korrekt) gelöst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2424556</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2424556</guid><dc:creator><![CDATA[highend]]></dc:creator><pubDate>Tue, 28 Oct 2014 16:27:19 GMT</pubDate></item><item><title><![CDATA[Reply to Verständnisproblem if-Abfragen-Bedingungen on Tue, 28 Oct 2014 18:16:24 GMT]]></title><description><![CDATA[<p>Ohne Klammern könntest du eigentlich ganz happy sein, daß dir dein Compiler nicht sagt &quot;Gehe zurück auf Los und steck dir unterwegs keine 2000 DM ein&quot;.</p>
<pre><code>int a = 1, b = 2, c = 0;

if (a == b == c)
{
	if (a == b)
	{
		cout &lt;&lt; &quot;A&quot; &lt;&lt; a;
	}
	else
	{
		cout &lt;&lt; &quot;B&quot; &lt;&lt; b;
	}
} 
else
{
	if (b == c)
	{
		cout &lt;&lt; &quot;C&quot; &lt;&lt; c;
	}
	else
	{
		cout &lt;&lt; &quot;HOPPLA&quot;;
	}
}
cout &lt;&lt; a &lt;&lt; b &lt;&lt; c;
</code></pre>
<p>Macht zwar genausowenig Sinn, sieht aber schon viel übersichtlicher aus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2424574</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2424574</guid><dc:creator><![CDATA[EOP]]></dc:creator><pubDate>Tue, 28 Oct 2014 18:16:24 GMT</pubDate></item></channel></rss>