C Program to Swap Two Numbers using Pointer

C Program to Swap Two Numbers using Pointer:
If you are using any software then below program will not give an error, but if you are using TURBO C then you have to make some changes like: void main() and some function like clrscr() or getch().



#include<stdio.h>

void swap(int *num1,int *num2)
{
   int temp;
   temp = *num1;
   *num1 = *num2;
   *num2 = temp;
}

main()
{
   int num1,num2;

   printf("Enter the first number : ");
   scanf("%d",&num1);
   printf("\nEnter the Second number : ");
   scanf("%d",&num2);

   swap(&num1,&num2);

   printf("\nFirst number is : %d", num1);
   printf("\nSecond number is : %d", num2);
}

OUTPUT:

Enter the first number : 5

Enter the Second number : 8

First number is : 8
Second number is : 5

Leave a Reply

Your email address will not be published. Required fields are marked *

five × 2 =

This site uses Akismet to reduce spam. Learn how your comment data is processed.