Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- include <stdio.h>
- const int b = 23;
- // A normal function with an int parameter and void return type
- void fun(int a)
- {
- if (a < b)
- printf("Value of a (%d) is lesser then value of b (%d)\n", a, b);
- else if (a == b)
- printf("Value of a (%d) is equal value of b (%d)\n", a, b);
- else if (a > b)
- printf("Value of a (%d) is greater than value of b (%d)\n", a, b);
- }
- // main
- int main(int argc, char **argv)
- {
- int i = 0;
- /* fun_ptr is a pointer to function fun()
- void (*fun_ptr)(int) = &fun;
- is equivalent of following two
- void (*fun_ptr)(int);
- fun_ptr = &fun;
- */
- void (*fun_ptr)(int) = &fun;
- // call once with static int
- (*fun_ptr)(b);
- // iterate through for loop
- for (i = 1; i < 101; i+=11) {
- // Invoking fun() using fun_ptr
- (*fun_ptr)(i);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement