function_pointers.c
author Markus Bröker <mbroeker@largo.dyndns.tv>
Tue, 13 Oct 2009 19:03:36 +0200
changeset 108 d6a52e0152fb
parent 103 be3fe4a4f097
child 140 05d42a3737a4
permissions -rw-r--r--
Compont Literals in C aka Anonymous arrays committer: Markus Bröker <mbroeker@largo.homelinux.org>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     1
/**
77
49e0babccb23 HEADER TAGS
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 27
diff changeset
     2
 * function_pointers.c
24
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     3
 */
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     4
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     5
#include <stdio.h>
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     6
#include <stdlib.h>
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     7
103
be3fe4a4f097 Function Pointer Demo simplified
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 77
diff changeset
     8
int plus (int a, int b)
24
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     9
{
103
be3fe4a4f097 Function Pointer Demo simplified
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 77
diff changeset
    10
    return a + b;
24
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    11
}
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    12
103
be3fe4a4f097 Function Pointer Demo simplified
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 77
diff changeset
    13
int minus (int a, int b)
24
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    14
{
103
be3fe4a4f097 Function Pointer Demo simplified
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 77
diff changeset
    15
    return a - b;
24
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    16
}
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    17
103
be3fe4a4f097 Function Pointer Demo simplified
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 77
diff changeset
    18
int func (int (*ptrFunc) (int, int), int a, int b)
24
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    19
{
103
be3fe4a4f097 Function Pointer Demo simplified
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 77
diff changeset
    20
    return ptrFunc (a, b);
24
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    21
}
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    22
27
81a574d60c15 typo in min2time format string
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 24
diff changeset
    23
int main (int argc, char **argv)
24
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    24
{
103
be3fe4a4f097 Function Pointer Demo simplified
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 77
diff changeset
    25
    printf ("Result: %d\n", func (&plus, 10, 20));
be3fe4a4f097 Function Pointer Demo simplified
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 77
diff changeset
    26
    printf ("Result: %d\n", func (&minus, 10, 20));
24
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    27
27
81a574d60c15 typo in min2time format string
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 24
diff changeset
    28
    return EXIT_SUCCESS;
24
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    29
}