26.6.20

call by value


CALL  BY VALUE:
void swap(int a,int b)
{

int t;
t=a;
a=b;b=t;

}
void main()
{
    int a=10,b=20;
    printf("Before swapping : %d,%d\n",a,b);
    swap(a,b);
    printf("After swapping : %d,%d\n",a,b);

}
OUTPUT
Before swapping : 10,20
After swapping :10,20
Explanation :the a,b in main() and swap() functions are different....
So the changes made to a and b in the swap() function has no affect on a and b of main().

No comments:

Post a Comment

JAVA program pattern 2

import java.util.Scanner; public class pattern3 { public static void main(String args[]) { int i,j; Scanner sc=new Scanner(System.in); Syste...