Turn Desktop View Off
by Dinesh Thakur

 This is C Program to Swap Two Numbers Using Pointer. In this program the two numbers to be swapped from each other place with the use of pointer this concept works on the address reference. In program the variables declare for storing the value in it. Here a variable named ‘temp’ also declared with the use of only two numbers the swapping will happen interference of temp variable the first number shifted to temp and then to other variable the reverse phase will be on the move to swap both numbers. And other functionality also comes in light for displaying the result on the screen.

Problem Statement: 
This is C Program to Swap Two Numbers Using Pointer condition.

  1. Declaring variable pointer type.
  2. Using swap condition.
  3. Display result on the screen.

Here is source code of the C program to Swap Two Numbers Using Pointer condition. The C program is successfully compiled. The program output is also shown below.


#include <stdio.h>

#include <conio.h>
void swap(float *d1 , float *d2)
{
    float temp;
    temp=*d1;
    *d1=*d2;
    *d2=temp;
}
void main()
{
    float a,b;
    clrscr();
    printf("Enter number a :");
    scanf("%f", &a);
    printf("\nEnter number b :");
    scanf("%f", &b);
    printf("\nBefore Swapping\n");
    printf("\na Contain %6.2f ",a);
    printf("\nb Contain %6.2f ",b);
    swap(&a,&b);
    printf("\nAfter Swapping\n");
    printf("\na Contain %6.2f ",a);
    printf("\nb Contain %6.2f ",b);
    getch();
}

Swap Two Numbers Using Pointer