Home > Programming > Functions using the "C" programming language > example13.c |
/*
In this example we demonstrate a function that takes as parameter a
pointer to structure (struct POINT)
*/
#include <stdio.h>
#include <conio.h>
/* struct POINT declaration */
struct POINT {
float x;
float y;
};
/* function doublePOINT prototype */
/*
Function doublePOINT takes as parameter a pointer to struct POINT
and doubles the field values.
*/
void doublePOINT( struct
POINT *);
/* function printPOINT prototype */
/*
Function printPOINT prints the fields of a struct POINT to screen
*/
void printPOINT( struct
POINT );
void main()
{
struct POINT p;
p.x = 1;
p.y = 1;
printPOINT( p );
doublePOINT( &p ); /* The symbol &p
corresponts to the memory reference */
/* of struct POINT p. */
printPOINT( p );
getch();
}
void doublePOINT( struct POINT *p)
{
p->x *= 2;
p->y *= 2;
}
void printPOINT( struct POINT p)
{
printf("x = %f.\ny = %f.\n\n",p.x,p.y);
}
© 2004 Jim Valavanis