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 294 views
1 answer 636 views
636 views asked Nov 30, 2019 by avibootz
2 answers 372 views
2 answers 143 views
1 answer 152 views
152 views asked May 16, 2022 by avibootz
2 answers 198 views
...