How to write a c program to swap the values of two variables by using call by reference in C Programming Language ?
Solution:
/*C Program to swap the values of two variables by using call by reference*/
#include<stdio.h>
#include<conio.h>
void swap(int *,int *);
void main()
{
int a,b,c;
clrscr();
printf("\nEnter the value of A & B:\n");
scanf("%d%d",&a,&b);
printf("\nBefore swapping values:");
printf("\n\tA=%d\n\tB=%d",a,b);
swap(&a,&b);
printf("\nAfter swapping values:");
printf("\n\tA=%d\n\tB=%d\n",a,b);
getch();
}
void swap(int *x,int *y)
{
int z;
z=*x;
*x=*y;
*y=z;
return(0);
}
//OUTPUT:
//Enter the value of A & B:10 20
//Before swapping values:
//A=10
//B=20
//After swapping values:
//A=20
//B=10
Learn More :
Swap
- C Program to Calculate Grid Size, Initialized Number onto tile, Initialize Tile Loop and If Grid is Even, Swap The Tiles Numbered 1 and 2
- C Program To Swap Two Numbers Without Using Third Variable
- C Program to Swap two variables without using third variable ?
- C Code/Program For Swap Matrix
- C Program To Swap two Numbers Using Pointers
- C Program To Swap Two numbers Without Third Variable
- C Program Swapping numbers using call by reference
- C Function to xorSwap and addSwap in C Programming
Value
- C Program to Demonstrates changing the keypad size and key values.
- C Program To Find The Maximum And Minimum Value In An Array
- C Program To Find Simple Interest
- C Program to Calculation of One Number Raised to Another
- C Program to find value of x by Pythagoras Theorem - Complex Number
- C Program to find result where value and power are user given
Two
- Write a c program to find out H.C.F. of two numbers.
- Write a C program to find maximum or equal between two numbers ?
- ADDITION OF TWO MATRICES USING C PROGRAM
- C Program To Find Product Of Two No Using MACRO
- C Program To Swap Two Numbers Without Using Third Variable
- C Program Concatenating Two Strings Into A Third System
- C Program to concatenate two strings without using string functions
- C Program to Interchanging Two Numbers
- C Program produsul scalar a doi vectori .
- C Program The dot product of two vectors
- C Program to two timing functions to measure process time
- C Program to calculate sum of two m*n matrices & store the result in 3 matrix
- Find the union and intersection of two sets of integer store it in two array C Program
- Menu driven program in C to Calculate Length, Copy into Another Compare Concatenate of Two String
- C Program To Multiply Two Polynomials
- Create Two Singly Linked List Perform Differences Display It C Program
- C Program to Input Student Details into a File For Two Subjects
- Adding two polynomial functions C Program Using Structure
- Program to Add Two Polynomials Using Linked List C Program
- Menu Driven Program to Read Two Integers Find Sum, Difference and Product C Program
- Input Two Numbers and Print Greater Number C Program
Call by Reference
Variables