function_pointers.c
author Markus Bröker <mbroeker@largo.dyndns.tv>
Mon, 07 Jun 2010 23:20:47 +0200
changeset 132 54a04f5f141d
parent 103 be3fe4a4f097
child 140 05d42a3737a4
permissions -rw-r--r--
Adjusted to show side effects and their handling When dealing with static buffers, successive calls point to the same memory location and overwrite formers ones... committer: Markus Bröker <mbroeker@largo.homelinux.org>

/**
 * function_pointers.c
 */

#include <stdio.h>
#include <stdlib.h>

int plus (int a, int b)
{
    return a + b;
}

int minus (int a, int b)
{
    return a - b;
}

int func (int (*ptrFunc) (int, int), int a, int b)
{
    return ptrFunc (a, b);
}

int main (int argc, char **argv)
{
    printf ("Result: %d\n", func (&plus, 10, 20));
    printf ("Result: %d\n", func (&minus, 10, 20));

    return EXIT_SUCCESS;
}