title: What is the result and example of invoking this function using "Call by name" in java or c++?
body: <p>I just took a quiz for my programming languages class and came across this question:</p>
  
  <p>Assuming call by name, what are the results of following code:</p>
  
  <pre><code>public class MyClass {
  
      static int i = 1;
  
      static float f(int x, int i){
          int s = 0;
          for(i = 0; i &lt;3; i++){
              s = s + x;
          }
          return s;
      }
  
      static void g(){
          int[] a= {10,30,50};
          int[] b = {20,40,60};
          System.out.println(f(i, i));
          i = 1;
          System.out.println(f(a[i],i));
          i = 1;
         System.out.println(f((a[i] *b[i]), i));
      }  
  
  
  
   public static void main(String[]args){
       g();
  
   }   
  }
  </code></pre>
  
  <p>The above code is exactly as presented on my quiz, but it was on paper at the time so I did the calculations manually and got the results <code>3.0, 90.0, and 3600.0</code>. After running the code on my own computer, the results are the same as what I calculated.</p>
  
  <p>However, the question was multiple choice and the closest option available was <code>3.0, 90.0, and 4400.0</code>. This leads me to assume that the words "Call by name" change how the function <code>f</code> is called on the line <code>System.out.println(f((a[i] *b[i]), i));</code></p>
  
  <p>Can someone please explain how 4400.0 is possible in Java or C++?</p>