Let's examine parameter passing by reference in greater detail...
The Program
/*********************************************
** File: ref_par.c
** Author: SAB
** Date: 7/7/98
** Section: 101
** SSN: 123-45-6789
** EMail: bogar@cs.umbc.edu
**
** This program demonstrates parameter
** passing by reference.
**********************************************/
#include
/* function prototype */
void F (int a, int * b);
int main()
{
int m, n ;
m = 3 ;
n = 5 ;
F(m, &n) ;
printf("%d, %d\n", m, n) ;
return 0;
}
/**********************************************
** Function F
** Inputs: an arbitrary integer, a
** a pointer to an integer, b
** Output: ???????
** there is no return value
**
** F is a function written to illustrate
** call by reference
**********************************************/
void F (int a, int * b)
{
a = 7 ;
*b = a ;
b = &a ;
*b = 4 ;
printf("%d, %d\n", a, *b) ;
}
The Sample Run
4, 4
3, 7
Last Modified - Thursday, 17-Jan-2002 13:52:23 EST