How to use function pointer in a while loop with C

1 Answer

0 votes
#include <stdio.h>

int Multiply(int x) {
    return x * 2;
}

int main() {
    int (*func_ptr)(int) = &Multiply;

    int i = 1;
    while (i <= 5) {
        printf("%d\n", (*func_ptr)(i));
        i++;
    }

    return 0;
}




/*
run:

2
4
6
8
10

*/

 



answered Mar 1, 2023 by avibootz

Related questions

1 answer 319 views
1 answer 643 views
643 views asked Nov 30, 2019 by avibootz
2 answers 388 views
2 answers 156 views
1 answer 164 views
164 views asked May 16, 2022 by avibootz
2 answers 210 views
...