Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22024

Function pointers that hold more functions

$
0
0

I am trying to create a function:

int func(int a, int b) { if (a == b) return 1; else return 0; }

Then I would like to create a function pointer like:

int (*ptr)(int, int);

How can I assign dynamically ptr to allow for it to hold, for example, 10 different function calls?

ptr[0] = func(1, 1);
ptr[1] = func(1, 0);
...
ptr[9] = func(0, 0);

So that I can call function inside FOR loop via pointer like:

int result = 0;
for (int i = 0; i < 10; i++)
    result += ptr[i];
printf ("%d\n", result);

Viewing all articles
Browse latest Browse all 22024

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>