Tuesday 5 March 2013

Program to show how to return more than one value from a function using call by reference

#include<stdio.h>
#include<conio.h>
func(int x, int y, int *ps, int *pd, int *pp);
main( )
{
int a, b, sum, diff, prod;
a = 6;
b = 4;
func( a, b, &sum, &diff, &prod );
printf("Sum = %d, Difference = %d, Product = %d\n", sum, diff, prod );
getch();
}
func(int x, int y, int *ps, int *pd, int *pp)
{
*ps = x+y;
*pd = x-y; 
*pp = x*y;    
}

No comments:

Post a Comment