Friday 1 June 2012

PROGRAM TO SWAP 2 VALUES USING POINTER


#include<stdio.h>
#include<conio.h>
void main()
            {
            int a,b,*p,*q,t;
            clrscr();
            printf("Enter the values of A and B: ");
            scanf("%d%d",&a,&b);
            printf("\nA=%d\nB=%d",a,b);
            p=&a;
            q=&b;
            t=*p;
            *p=*q;
            *q=t;
            printf("\n\nSwapped numbers \n");
            printf("\nA=%d\nB=%d",a,b);
            getch();
            }


OutPut
  ---------
Enter the values of A and B: 2 5

A=8
B=3

Swapped numbers

A=3
B=8

No comments:

Post a Comment