Write a program to interchange or swap two numbers using pointers.

C File =>


/* Write a program to interchange two numbers using pointers.*/


#include<stdio.h>
int main ()
{
   int a=5,b=8;
   void swap(int *a,int *b)
  {
      int temp=0;
      temp = *a;
      *a=*b;
     *b = temp;
    }
   printf("Before calling function:\n");
   printf("a=%d and b=%d",a,b);
   swap(&a,&b);
   printf("\n After calling function:\n");
   printf("a=%d and b=%d",a,b);
   return 0;
}

Comments

Popular posts from this blog

Write a program to allocate memory dynamically for n integers. Accept the elements and calculate their sum and average

C program to accept names of n cities and search for city named “Pune”.