What is Pass by Reference?
Harsh Gaikwad
XR Developer@Virtual Elements Studio XR Game Developer ll Unreal Engine Game developer || Unity ll Blender 3d || UEFN || Android developer
//Code on Array I know I have not given You idea about arrays and their
declaration but i still suggest u try this code
public class Dsa3
? ? public static void update(int marks[],int nonchangeable){
? ? ? ? nonchangeable=10;
? ? ? ? for (int i = 0; i < marks.length; i++) {
? ? ? ? ? ? marks[i]=marks[i]+1;
? ? ? ? ? ?
? ? ? ? }
? ? }
? ? public static void main(String args[]){
? ? ? ? int marks[]={12,21,32}; ?// Call by reference type-->this value changes
? ? ? ? int nonchangeable=5; // Call by value ?this value remains unchanged
? ? ? ? update(marks,nonchangeable);
? ? ? ? System.out.println(nonchangeable);
? ? ? ?
? ? ? ? for (int i = 0; i < marks.length; i++) {
? ? ? ? ? ? System.out.println("Marks are "+ marks[i]);
? ? ? ? ? ?
? ? ? ? }
? ? }
? ? //Array is Call by reference ds hai isliye values main Function mai change hogayi jab smaller function mai change lagaya
? ? //Agar Call by value hoti to ye possible nahi tha bez call by value does not have any effect on main when smaller function updates a dvalue
}{