Call by reference ( Example )

Ranjeet_8
Posted by Ranjeet_8 under C# category on | Points: 40 | Views : 1142
Call by reference:
void swap(int *x, int *y)

{
int temp;
temp = *x;
*x = *y;
*y = temp;
printf("Swapped values are a = %d and b = %d", *x, *y);
}
void main()
{
int a = 7, b = 4;
swap(&a, &b);
printf("Original values are a = %d and b = %d",a,b);
printf("The values after swap are a = %d and b = %d",a,b);
}

Output:
Original Values are a = 7 and b = 4
Swapped values are a = 4 and b = 7

Comments or Responses

Login to post response