C program to swap two numbers without using third variable, Swapping means to interchange of two numbers. In this program to Swapping two numbers without using third variables And Also use Call by Reference Functions.
Swapping of two Without Third Variable numbers in C program codes
#include<stdio.h>
#include<conio.h>
void swap(*int,*int);
void main()
{
int a, b;
clrscr();
printf("\n Enter the two values of a And b ");
scanf("%d%d",&a, &b);
swap(&a,&b);
printf("\n After Swapping a = %d\t, b = %d",a,b);
getch();
}
void swap(int *a,int *b)
{
*a = *a + *b;
*b = *a - *b;
*a = *a - *b;
}
Output:-

Swapping of two Without Third Variable numbers in C program codes
#include<stdio.h>
#include<conio.h>
void swap(*int,*int);
void main()
{
int a, b;
clrscr();
printf("\n Enter the two values of a And b ");
scanf("%d%d",&a, &b);
swap(&a,&b);
printf("\n After Swapping a = %d\t, b = %d",a,b);
getch();
}
void swap(int *a,int *b)
{
*a = *a + *b;
*b = *a - *b;
*a = *a - *b;
}
Output:-
