Sign in

gwj / po_oopc · Files

GitLab

  • Go to dashboard
  • Project
  • Activity
  • Files
  • Commits
  • Network
  • Graphs
  • po_oopc
  • examples03
  • 00-funptr
  • funptr.c
  • Reformatted code
    c0b14c54
    Grzegorz Jabłoński authored
    2022-09-16 14:36:36 +0200  
    Browse Code »
funptr.c 431 Bytes
Edit Raw Blame History
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
#include <stdio.h>

int* f1(int* a, const int* b)
{
    *a += *b;
    return a;
}

int* f2(int* a, const int* b)
{
    *a -= *b;
    return a;
}

int* (*fun(int s))(int*, const int*)
{
    if (s == 1)
        return f1;
    else
        return f2;
}

int main()
{
    int* (*(*fp2)(int))(int*, const int*) = fun;

    int a = 15;
    int b = 32;
    fp2(1)(&a, &b);
    fp2(2)(&b, &a);
    printf("%d %d\n", a, b);
    return 0;
}