What is Pass by Reference?

What is Pass by Reference?

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
//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




}{        

要查看或添加评论,请登录

Harsh Gaikwad的更多文章

  • Pass By Value??

    Pass By Value??

    //Swapping Code //try declaring the call values in main and local function both and see the differenece public class…

    1 条评论
  • Method Overloading

    Method Overloading

    public class Challenge30day4 { ? ? public static int area(int a){ ? ? ? ? System.out.

    1 条评论
  • Competitive Coding Experience

    Competitive Coding Experience

    Hey, Connections..

    1 条评论
  • Codes and Problems on Functions

    Codes and Problems on Functions

    So Hey Connections Sorry for the Delay..

    1 条评论
  • What are Functions?

    What are Functions?

    A function is basically a type of method that returns a value after performing its task. The thing is people usually…

  • First Slot of Java Programming

    First Slot of Java Programming

    So hey Connections.Hi there!!! So am bringing up a 30 days Java programming Code Challenge Where we gonna learn and…

    1 条评论

社区洞察

其他会员也浏览了