Home > Programming > Functions using the "C" programming language > example11.c |
/*
In this example we demonstrate how to pass a pointer to integer
as a parameter to a function
*/
#include <alloc.h>
#include <stdio.h>
/*
Function prototype
*/
void print_ptr(int *);
void main()
{
int *px; /* Pointer
declaration */
px = (int *) malloc ( 1 ); /* Allocate memory */
*px = 5;
print_ptr( px );
free( px ); /* Free up memory */
}
/*
Function print_ptr source code
*/
void print_ptr(int *p)
{
printf("%d\n",*p);
}
© 2004 Jim Valavanis