Function Program24

// With return value, with argument: swapping of two numbers


#include<stdio.h>

#include<conio.h>


int swap(int *, int *);


void main()

{

int a, b;

clrscr();


printf("\nEnter value of a: ");

scanf("%d", &a);


printf("\nEnter value of b: ");

scanf("%d", &b);


printf("\n\nBefore swaping\tA: %d\tB: %d", a, b);

// Function return only one value

// We need here more than one value, so we are passing reference

swap(&a, &b);

printf("\n\nAfter swaping\tA: %d\tB: %d", a, b);


getch();

}


int swap(int *a, int *b)

{

int temp;

temp = *a;

*a = *b;

*b = temp;

}


No comments:

Post a Comment