Home » Sometech » WAP to demonstrate the concept of function call by value and call by reference.

WAP to demonstrate the concept of function call by value and call by reference.

#include <stdio.h>

#include<conio.h>

void swap1(int ,int );

void swap2(int * ,int * );

 

int main()

{

 

    int i = 10, j = 5;

    clrscr();

    printf(“\nBefore call by value…”);

printf(“\n i=%d and j=%d”,i,j);

 

swap1(i,j);

printf(“\nAfter call by value…”);

printf(“\n i=%d and j=%d”,i,j);

 

printf(“\nBefore call by address…”);

printf(“\n i=%d and j=%d”,i,j);

 

swap2(&i, &j);

printf(“\nAfter call by address…”);

printf(“\n i=%d and j=%d”,i,j);

 

  return 0;

}

void

swap1(int x, int y)

{

    int temp = x;

    x = y;

    y = temp;

}

 

 

 

 

 

void swap2(int * x, int* y)

{

 

    int temp = *x;

    *x = *y;

    *y = temp;

}

 

Advertisements

SoME Tech

Error: Twitter did not respond. Please wait a few minutes and refresh this page.

%d bloggers like this: