Yes.
It looks as if there is a contradiction here:
int variable in main().int array in main().Actually, there is no contradiction here. Remember that an array is an object. When an object is a parameter, the called method gets a reference to the object, not a copy of the object.
In the example, the zeroElt()
method gets a reference to the array object.
Since the parameter x refers to the array,
the method may change the array by using x.
The picture shows this.
This is still call by value,
as always,
because when the method call cng.zeroElt(value, 0)
is executed,
the parameter x of the method
gets the
value
held in the variable
value,
which is a reference to the array.
Since the method zeroElt() has a reference to the array,
can it change individual array elements?