Home > Programming > Functions using the "C" programming language > example15.c

 

Previous

Next


/*
    In this example we demonstrate a function that returns a pointer to a global
    variable of type union
*/
#include <stdio.h>
#include <conio.h>


/*
    union NUMBER declaration
*/

union NUMBER {
    int i;
    long l;
};

/*
    Global variable of type union NUMBER declaration
*/

union NUMBER number;

/*
    Function prototype.
*/

union NUMBER *get_global_ptr();

void main()
{
   /* Put a value to our variable */
    number.l = 0xFFFF;
    printf("Number value is %ld",get_global_ptr()->l);
    getch();
}

/*
    Function get_global_ptr code.
    Returns a pointer to the global variable number.
*/
union NUMBER *get_global_ptr()
{
    return &number;
}


© 2004 Jim Valavanis

Previous

Next

1