Skip to main content

C Program to swap two numbers using pointers and function.

C Program to swap two numbers using pointers and function.  



#include <stdio.h>

void swap(int *a,int *b);


int main()

{
  int num1=5,num2=10;


  swap(&num1,&num2);
       /* address of num1 and num2 is passed to swap function */

  
  printf("Number1 = %d\n",num1);
  printf("Number2 = %d",num2);
  

  return 0;
}


void swap(int *a,int *b)

{
 /* pointer a and b points to address of num1 and num2 respectively */
  int temp;
  temp=*a;
  *a=*b;
  *b=temp;
}




Comments

Popular posts from this blog

C Program to print the pattern

C Program to print the pattern X X Y X Y Z ........................................................................................ #include<stdio.h> #include<conio.h> void main () { int i , j ; for ( i= 88 ; i< 91 ;i ++) { for ( j = 88 ;j <= i ; j ++) { printf ( "%c" , j );                    }           printf ( "\n" ); } getch (); } ........................................................................................ OUTPUT

Deen Dayal Upadhyay Gorakhpur University RESULTS

DDU Gorakhpur results chahiye to yaha click kare                                                                       RESULTS  

Computer Science B.Sc2nd Practical 2016

             Deen Dayal Upadhyaya Gorakhpur University                            Computer Science B.Sc2nd Practical 2016