Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I will try to explain an example of pre and post increment from which you can solve the question posted yourself.</p> <pre><code>#include &lt;iostream&gt; void foo(int num) { std::cout &lt;&lt; num &lt;&lt; "\n" ; } int main() { int number = 10 ; foo( number++ ) ; foo( ++number ) ; foo( number + 1 ) ; getchar() ; return 0 ; } </code></pre> <p><strong>Output:</strong></p> <blockquote> <p>10<br> 12<br> 13 </p> </blockquote> <p><strong>Why 10?</strong></p> <pre><code>foo( number++ ) ; </code></pre> <p><em>Post-increment</em> operation is done on <strong>number</strong>. Meaning, value of <strong>number</strong> is first passed to <code>foo</code> and then the value of <strong>number</strong> is incremented upon <code>foo</code> return. So, after function return, <strong>number</strong> is 11.</p> <p><strong>Why 12?</strong></p> <pre><code>foo( ++number ) ; </code></pre> <p><em>Pre-increment</em> operation is done on <strong>number</strong>. Meaning, before even call to <code>foo</code>, the value of <code>number</code> is incremented to 12. And then it is passed to <code>foo</code>. So, even after the function return, <strong>number</strong> is still 12.</p> <p><strong>Why 13?</strong></p> <p>It's just straight forward. Value of <strong>number</strong> is not modified but passed a value adding 1 to the value of <strong>number</strong>. In this process, <strong>number</strong> is not modified. So, even after function return, <strong>number</strong> is still 12.</p> <p>Hope this helps to solve the problem yourself ( though in your case it is paper-pencil exercise ) :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload