<?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[wie entstehen diese Ausgaben]]></title><description><![CDATA[<p>Hallo!<br />
Wir sind gerade dabei einer Musterklausur in Info durchzuarbeiten. Dabei werden auch Quellcodes abgefragt. Hier darunter ist solch ein Prachtexemplar. Diese sind aber manchmal so verworren das ich schwierigkeiten habe da durchzusteigen weil ich nie so programmieren würde.<br />
Meine Frage zu dem unteren Code ist.<br />
Wie kommt man auf die 60 und dann wieder auf 14. a wird doch wieder mit 8 initilaisiert a+b--&gt;8+6=14 ok! Aber wieso dann eben oben 60. Und wieso wird es dann außerhalb in der Klammer dann 126. 46 und 52 ist mir klar.<br />
Bitte helft mir diesen Quellcode zu verstehen</p>
<p>Gruß niesel</p>
<pre><code class="language-cpp">#include&lt;iostream.h&gt;
int a=20,b=30;
int f1(int p, int b)
{     return a=a+p+b;    }
int f2(int a, int b)
{     return a=a+b;      }
void main()
{
    int b=6;

    cout &lt;&lt; f1(a,b) &lt;&lt;&quot;\n&quot;;      //Ausgabe = 46

    cout &lt;&lt; f2(a,b) &lt;&lt;&quot;\n&quot;;      //Ausgabe = 52
    {
         int a=8;

         cout &lt;&lt; f1(a,b) &lt;&lt;&quot;\n&quot;; //Ausgabe = 60

         cout &lt;&lt; f2(a,b) &lt;&lt;&quot;\n&quot;; //Ausgabe = 14
    }

    cout &lt;&lt; f1(a,b) &lt;&lt;&quot;\n&quot;;//Ausgabe = 126
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/173565/wie-entstehen-diese-ausgaben</link><generator>RSS for Node</generator><lastBuildDate>Fri, 18 Sep 2026 07:43:36 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/173565.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 17 Feb 2007 09:15:58 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to wie entstehen diese Ausgaben on Sat, 17 Feb 2007 09:15:58 GMT]]></title><description><![CDATA[<p>Hallo!<br />
Wir sind gerade dabei einer Musterklausur in Info durchzuarbeiten. Dabei werden auch Quellcodes abgefragt. Hier darunter ist solch ein Prachtexemplar. Diese sind aber manchmal so verworren das ich schwierigkeiten habe da durchzusteigen weil ich nie so programmieren würde.<br />
Meine Frage zu dem unteren Code ist.<br />
Wie kommt man auf die 60 und dann wieder auf 14. a wird doch wieder mit 8 initilaisiert a+b--&gt;8+6=14 ok! Aber wieso dann eben oben 60. Und wieso wird es dann außerhalb in der Klammer dann 126. 46 und 52 ist mir klar.<br />
Bitte helft mir diesen Quellcode zu verstehen</p>
<p>Gruß niesel</p>
<pre><code class="language-cpp">#include&lt;iostream.h&gt;
int a=20,b=30;
int f1(int p, int b)
{     return a=a+p+b;    }
int f2(int a, int b)
{     return a=a+b;      }
void main()
{
    int b=6;

    cout &lt;&lt; f1(a,b) &lt;&lt;&quot;\n&quot;;      //Ausgabe = 46

    cout &lt;&lt; f2(a,b) &lt;&lt;&quot;\n&quot;;      //Ausgabe = 52
    {
         int a=8;

         cout &lt;&lt; f1(a,b) &lt;&lt;&quot;\n&quot;; //Ausgabe = 60

         cout &lt;&lt; f2(a,b) &lt;&lt;&quot;\n&quot;; //Ausgabe = 14
    }

    cout &lt;&lt; f1(a,b) &lt;&lt;&quot;\n&quot;;//Ausgabe = 126
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1229987</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1229987</guid><dc:creator><![CDATA[nieselfriem]]></dc:creator><pubDate>Sat, 17 Feb 2007 09:15:58 GMT</pubDate></item><item><title><![CDATA[Reply to wie entstehen diese Ausgaben on Sat, 17 Feb 2007 09:48:35 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;iostream&gt;
short a_global = 20;
short b_global = 30;

short f1(short p_param, short b_param)
{     
    return (a_global += p_param + b_param);    
}

short f2(short a_param, short b_param)
{
    return (a_param += b_param);
}

int main()
{
    short b_local = 6;

    std::cout &lt;&lt; f1(a_global, b_local) &lt;&lt; std::endl;
    // 20 += 20 + 6 =&gt; 46 == a_global                             
    std::cout &lt;&lt; f2(a_global, b_local) &lt;&lt; std::endl;
    // a_global == 46  ... Rückgabe = (a_global[46] + b_local[6])
    {
        short a_local = 8;

        std::cout &lt;&lt; f1(a_local, b_local) &lt;&lt; std::endl; // 46 + 8 + 6 // Ausgabe sollte wohl eigentlich 66 sein ...
        std::cout &lt;&lt; f2(a_local, b_local) &lt;&lt; std::endl; // 8 + 6 == 14
    }                            
    std::cout &lt;&lt; f1(a_global, b_local) &lt;&lt; std::endl; // 60 + 60 + 6 sollte das eigentlich sein ... = 126

    return 0;
}
</code></pre>
<p>So ... dein Lehrer sollte sich mal angucken was der fürn Müll programmiert hat ... sein Code ist kein Standard C++ ...</p>
<p>Hmmm warum das so ist? Weil dein Wert der Übergebenen Variablen bei f2 gleich bleibt ... musst schon Pointer oder Referenzen nehmen damit sich da was ändert <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/1229993</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1229993</guid><dc:creator><![CDATA[*D*Evil]]></dc:creator><pubDate>Sat, 17 Feb 2007 09:48:35 GMT</pubDate></item></channel></rss>