function_pointers.c
author Markus Bröker <mbroeker@largo.dyndns.tv>
Fri, 19 Nov 2010 12:23:24 +0100
changeset 158 2cddd4d26139
parent 140 05d42a3737a4
permissions -rw-r--r--
removed unnecessary #includes 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
140
05d42a3737a4 Comments corrected: misspellings and other trivial things
Markus Bröker <mbroeker@volpe.spectre.org>
parents: 103
diff changeset
     3
 * Copyright (C) 2009 Markus Broeker
24
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
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     6
#include <stdio.h>
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     7
#include <stdlib.h>
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     8
103
be3fe4a4f097 Function Pointer Demo simplified
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 77
diff changeset
     9
int plus (int a, int b)
24
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    10
{
103
be3fe4a4f097 Function Pointer Demo simplified
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 77
diff changeset
    11
    return a + b;
24
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    12
}
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    13
103
be3fe4a4f097 Function Pointer Demo simplified
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 77
diff changeset
    14
int minus (int a, int b)
24
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    15
{
103
be3fe4a4f097 Function Pointer Demo simplified
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 77
diff changeset
    16
    return a - b;
24
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    17
}
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    18
103
be3fe4a4f097 Function Pointer Demo simplified
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 77
diff changeset
    19
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
    20
{
103
be3fe4a4f097 Function Pointer Demo simplified
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 77
diff changeset
    21
    return ptrFunc (a, b);
24
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    22
}
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    23
27
81a574d60c15 typo in min2time format string
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 24
diff changeset
    24
int main (int argc, char **argv)
24
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    25
{
103
be3fe4a4f097 Function Pointer Demo simplified
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 77
diff changeset
    26
    printf ("Result: %d\n", func (&plus, 10, 20));
be3fe4a4f097 Function Pointer Demo simplified
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 77
diff changeset
    27
    printf ("Result: %d\n", func (&minus, 10, 20));
24
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    28
27
81a574d60c15 typo in min2time format string
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 24
diff changeset
    29
    return EXIT_SUCCESS;
24
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    30
}