UncleCoder.com

UncleCoder.com

Free programming examples and instructions

C program to swap to numbers using pointer

C program for how to swap two numbers using pointers

by Krishna viswambharan


Posted on 31 Oct 2017 Category: C Views: 272

Edited on 02 Jun 2018


C program to swap to numbers using pointers

This article explains a C program to swap to numbers using pointers. Source code and output is also shown below.

#include <stdio.h>
#include <conio.h>
void swap(int *,int*);
void main()
{
      int a=10,b=20;
      swap(&a,&b);
      printf(ā€œ\nSwapped form\nā€);
      printf(ā€œ%d\t%dā€,a,b);
      getch();
}
void swap(int *ptr1,int *ptr2)
{
     int temp;
     temp=*ptr1;
     *ptr1=*ptr2;
     *ptr2=temp;
}

output



Leave a Comment:


Advertisement