Example. A puzzling question

[comp1110-1P]

Without running this program, try to deduce what it will output:

void fun1(int[] arr) { arr[0] = 100; } void fun2(int[] arr) { arr = new int[]{5,4,3,2,1}; } void fun3(int i) { i = 200; } void main() { int[] arr = new int[]{1,2,3,4,5,6}; int i = arr[0]; fun1(arr); IO.println(arr[0]); IO.println(i); fun2(arr); IO.println(arr[0]); IO.println(i); fun3(i); IO.println(arr[0]); IO.println(i); }

You will only get the answer correct if you understand what happens in Java when values are passed to functions.

bars magnifying-glass caret-down plus minus arrow-right xmark