Home > Programming > Functions using the "C" programming language > example12.c |
/*
In this example we demonstrate how to pass two pointers to long
as parameters to a function
*/
#include <stdio.h>
/*
Function prototype
*/
void swap_nums(long *, long *);
void main()
{
// We declare two long variables l1 and l2
long l1 = 1;
long l2 = 2;
printf("Before swaping : l1 = %ld, l2 = %ld.\n",l1,l2);
// Note: The & symbol before a variable represends a pointer to
the variable
swap_nums(&l1, &l2);
printf("After swaping : l1 = %ld, l2 = %ld.\n",l1,l2);
}
/*
Function swap_nums source code
*/
void swap_nums(long *p1, long *p2)
{
long t = *p1;
*p1 = *p2;
*p2 = t;
}
© 2004 Jim Valavanis