<?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[[gelöst] Funktionen und if-Abfragen]]></title><description><![CDATA[<p>Hi,</p>
<p>ich habe mal wieder eine Frage, da ich dem C++ Primer nicht ganz folgen kann.<br />
Dort steht:</p>
<blockquote>
<p>A function terminates after executing a return statement. If a function has more than one return statemant - for example, as alternatives to different <strong>if else</strong> selections - the function terminates after it executes the first return statemant it reaches:</p>
<pre><code>int bitter(int a, int b)
{
  if(a &gt; b)
   return a; // if a &gt; b, function terminates here
  else
   return b; // otherwise, function terminates here
}
</code></pre>
<p>Here the <strong>else</strong> isn't needed, but it does help the casual reader understand the intent.</p>
</blockquote>
<p>Und jetzt verstehe ich den letzten Satz einfach nicht.<br />
Die Beschreibung sagt, dass eine Funktion endet, wenn ein return erreicht ist. Ja aber bei einer if-Abfrage kann es doch sein, dass der Block nicht ausgeführt wird.<br />
Also wenn ich wie oben beschrieben das 'else' wegnehme und es gilt a &lt; b, ja was passiert denn dann?<br />
Der if(a &gt; b) Block wird nicht ausgeführt und das return b existiert nicht.</p>
<p>Was macht die Funktion denn dann?</p>
<p>Gruß,<br />
Klaus.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/302892/gelöst-funktionen-und-if-abfragen</link><generator>RSS for Node</generator><lastBuildDate>Tue, 11 Aug 2026 02:08:07 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/302892.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 30 Apr 2012 09:56:34 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [gelöst] Funktionen und if-Abfragen on Mon, 30 Apr 2012 10:02:51 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>ich habe mal wieder eine Frage, da ich dem C++ Primer nicht ganz folgen kann.<br />
Dort steht:</p>
<blockquote>
<p>A function terminates after executing a return statement. If a function has more than one return statemant - for example, as alternatives to different <strong>if else</strong> selections - the function terminates after it executes the first return statemant it reaches:</p>
<pre><code>int bitter(int a, int b)
{
  if(a &gt; b)
   return a; // if a &gt; b, function terminates here
  else
   return b; // otherwise, function terminates here
}
</code></pre>
<p>Here the <strong>else</strong> isn't needed, but it does help the casual reader understand the intent.</p>
</blockquote>
<p>Und jetzt verstehe ich den letzten Satz einfach nicht.<br />
Die Beschreibung sagt, dass eine Funktion endet, wenn ein return erreicht ist. Ja aber bei einer if-Abfrage kann es doch sein, dass der Block nicht ausgeführt wird.<br />
Also wenn ich wie oben beschrieben das 'else' wegnehme und es gilt a &lt; b, ja was passiert denn dann?<br />
Der if(a &gt; b) Block wird nicht ausgeführt und das return b existiert nicht.</p>
<p>Was macht die Funktion denn dann?</p>
<p>Gruß,<br />
Klaus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2206877</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2206877</guid><dc:creator><![CDATA[Klaus82]]></dc:creator><pubDate>Mon, 30 Apr 2012 10:02:51 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst] Funktionen und if-Abfragen on Mon, 30 Apr 2012 10:01:09 GMT]]></title><description><![CDATA[<p>Klaus82 schrieb:</p>
<blockquote>
<p>...</p>
<blockquote>
<p>Here the <strong>else</strong> isn't needed, but it does help the casual reader understand the intent.</p>
</blockquote>
<p>Also wenn ich wie oben beschrieben das 'else' wegnehme und es gilt a &lt; b, ja was passiert denn dann?<br />
Der if(a &gt; b) Block wird nicht ausgeführt und das return b existiert nicht.</p>
</blockquote>
<p>Das &quot;else&quot; ist unnötig, nicht das &quot;return b&quot;:</p>
<pre><code class="language-cpp">// Hier ohne das else
int bitter(int a, int b)
{
  if(a &gt; b)
    return a;
  return b;
}
</code></pre>
<p>Das ist damit gemeint.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2206878</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2206878</guid><dc:creator><![CDATA[asc]]></dc:creator><pubDate>Mon, 30 Apr 2012 10:01:09 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst] Funktionen und if-Abfragen on Mon, 30 Apr 2012 10:01:15 GMT]]></title><description><![CDATA[<p>Mit &quot;'else' wegnehmen&quot; ist folgendes gemeint:</p>
<pre><code class="language-cpp">int bitter(int a, int b)
{
  if(a &gt; b)
   return a; // if a &gt; b, function terminates here

 return b; // otherwise, function terminates here
}
</code></pre>
<p>Und dies ist semantisch das gleiche wie mit 'else'.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2206879</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2206879</guid><dc:creator><![CDATA[Th69]]></dc:creator><pubDate>Mon, 30 Apr 2012 10:01:15 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst] Funktionen und if-Abfragen on Mon, 30 Apr 2012 10:02:20 GMT]]></title><description><![CDATA[<p>Ach soooo.</p>
<p>Sorry, dann macht das natürlich Sinn.</p>
<p>Gruß,<br />
Klaus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2206880</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2206880</guid><dc:creator><![CDATA[Klaus82]]></dc:creator><pubDate>Mon, 30 Apr 2012 10:02:20 GMT</pubDate></item></channel></rss>