Monday, July 13, 2015

Pointers and functions

#include <stdio.h>

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

int main()
{
  int num1=5,num2=10;

  printf("Before swapping: num1=%d  num2=%d",num1,num2);

  swap(&num1,&num2); 

  printf("\n After  swapping:num1=%d  num2=%d",num1,num2);

  return 0;
}
void swap(int *a,int *b)
{
  int temp;

  temp=*a;
  *a=*b;
  *b=temp;
}


output:


Before swapping: num1=5  num2=10

 After  swapping:num1=10  num2=5

No comments:

Post a Comment