Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would say that's a complex example if you are being taught about pointers!</p> <blockquote> <p>Is there some kind of conversion happening in the function's arguments that turn p1, p2, &amp;il, and &amp;i2 to the value (*) of a pointer? Like p1 turns into *p1?</p> </blockquote> <p><code>p1</code> and <code>p2</code> are declared as <code>int *</code> (pointer to <code>int</code>) and are initialised with the address of <code>i1</code> and <code>i2</code> (using the <code>&amp;</code> operator).</p> <blockquote> <p>I thought a copy of the variable was passed into the function instead of the actual variable, so why was the value of the passed in variable changed after the function?</p> </blockquote> <p>A copy of the variable is passed to the function, however in this case the variable of type <code>int *</code> (pointer to <code>int</code>). The reason the value is changing is because the <code>exchangeValues()</code> function is dereferencing those pointers and swapping the values. This is the only way (in C/Objective-C) a function can modify a variable outside of its own scope, other than the variable being assigned as the return value from a function.</p> <blockquote> <p>Also why am I getting a warning on the 3rd line that says: No previous prototype for function 'exchangeValues'?</p> </blockquote> <p>You seem to have typed it in wrong; remove the line below <code>@autoreleasepool</code>:</p> <pre><code>@autoreleasepool { void exchangeValues (int *pint1, int *pint2); &lt;-- delete this line </code></pre>
    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. 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.
 

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