Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The type of <code>addition</code> is <code>int (&amp;)(int,int)</code> which can decay into a pointer of type <code>int (*)(int,int)</code> which is same as that of <code>operation</code> function's third parameter. So you can pass <code>addition</code> as third argument to the function <code>operation</code>. </p> <p>The type of <code>subtraction</code> is also the same as that of <code>addition</code>. In your code, the address of <code>subtraction</code> is first stored as local variable of the compatible type, and then that variable is passed as argument to <code>operation</code> function. </p> <p>In case of <code>addition</code>, it's address is not stored as local variable, instead its passed as such to <code>operation</code>. Its initializing the function's third parameter directly with the function's address, without using any local variable. </p> <p>A conversion from <code>int (&amp;)(int,int)</code> to <code>int (*)(int,int)</code> occurs in both cases. Its just that with <code>substration</code>, the conversion occurs when initializing the local variable, and with <code>addition</code>, the conversion occurs when initializing the function parameter.</p> <p>An analogy would be this:</p> <pre><code>void f(double a, double b) {} int main() { double x = 100;//first store 100 in a local variable f(x, 100); //pass the local variable as first arg, //and pass 100 as second arg without using any local variable. } </code></pre> <p>Note the type of <code>100</code> is <code>int</code>, so it first converts to <code>double</code> type, which is then stored as local variable <code>x</code>, which in turn is passed to the function <code>f</code> as first argument. And the second argument <code>100</code> is passed directly to the function, so even now it first converts to <code>double</code> and then it initializes <code>b</code> (the second parameter of the function). </p> <p>Again, a conversion from <code>int</code> to <code>double</code> occurs in both cases. Its just that first argument conversion occurs when initializing the local variable <code>x</code>, and second argument conversion occurs when initializing the <em>second</em> parameter of the function. </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.
 

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