26.6.20

call by address /reference example 1


CALL BY ADDRESS/REFERENCE EXAMPLE 1:
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 20,10

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...