To swap the address of two variables using pointer


Levels of difficulty: / perform operation:

C program to swap the address of two variables.

C Program

#include <stdio.h>
#include <conio.h>
void swap(int *,int *);
void main()
{
	int a=10,b=20;
	clrscr();
	printf("\nVALUES OF a AND b BEFORE SWAPING ARE %d %d",a,b);
	swap(&a,&b);
	printf("\nVALUES OF a AND b AFTER SWAPING ARE %d %d",a,b);
	getch();
}
void swap(x,y)
int *x,*y;
{
	int t;
	t=*x;
	*x=*y;
	*y=t;
}


Output







Quantitative Aptitude
Reasoning
Programming
Interview