Function Pointer in C

Function Pointer in C

#include<stdio.h>

void swap(int*,int*) ;

main()
{

 int a,b;
 printf("Enter Value of A:");
 scanf("%d",&a);

 printf("Enter Value of B:");
 scanf("%d",&b);

  printf("Before Swap:\na=%d\nb=%d\n",a,b);     // a and b value before swap

   swap(&a,&b);

  printf("After Swap:\na=%d\nb=%d\n",a,b);     // a and b value after swap

}
void swap(int *x,int *y)

{
 int t;       //temporary variable to store value of a/b
  t=*x;
  *x=*y;
  *y=t;     //without return type we change value of a and b.becuz a and b 's address passed instead of value.and return multiple value which possible only using pointer

}

Related Posts