Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Update</strong>: The answer is 12, see update below.</p> <p>OK, this is actually a good question. So this explains what "copy-restore" is all about: <a href="https://stackoverflow.com/a/8871340/171933">https://stackoverflow.com/a/8871340/171933</a></p> <p>Most programming languages don't support copy/restore, but only (some variations) of pass-by-value and pass-by-reference. So it's not so easy to try this out.</p> <p>However, the question you are interested in is this: Which value wins? Does <code>x</code> get to write its value back to <code>a</code> when the function ends (which would be 11), or does <code>y</code> get to write its value back to <code>a</code> when the function ends (which would be 12).</p> <p>In a language that supports "copy-restore", I'd hope that this would throw a compiler error.</p> <p><strong>Update</strong>:</p> <p>After some searching I've found a language that actually supports "copy-restore", namely Ada. This is the code in Ada (this is my first and probably last program written in Ada):</p> <pre><code>with Ada.Text_IO; use Ada.Text_IO; procedure copy_restore_example is a: integer; procedure p(x: in out integer; y: in out integer) is begin x:= x+1; y:= y+2; end p; begin a := 10; Put_Line("Before :" &amp; natural'image(a)); p(a, a); Put_Line("After :" &amp; natural'image(a)); end copy_restore_example; </code></pre> <p>The result is <strong>12</strong>, <code>y</code> wins. You can run this program in your browser here: <a href="http://www.compileonline.com/compile_ada_online.php" rel="nofollow noreferrer">http://www.compileonline.com/compile_ada_online.php</a></p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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