B
bwaichu
I'm struggling with the concept of function pointers. I understand
that a function pointer contains the memory address of the function.
But I'm not sure how they are effectively used, and I'm not 100% sure
on their syntax.
This is a program I wrote to give myself an idea of how to use them.
But I'm not quite getting it. And I'm not sure what the syntax is for
a function pointer with parameters.
#include <stdio.h>
void foo(void (*)());
void foo2(void);
int
main(int argc, char **argv) {
foo(&foo2);
return 0;
}
void
foo(void (*name)()) {
(void)printf("in foo\n");
(name)();
return;
}
void
foo2(void) {
(void)printf("in foo2\n");
return;
}
that a function pointer contains the memory address of the function.
But I'm not sure how they are effectively used, and I'm not 100% sure
on their syntax.
This is a program I wrote to give myself an idea of how to use them.
But I'm not quite getting it. And I'm not sure what the syntax is for
a function pointer with parameters.
#include <stdio.h>
void foo(void (*)());
void foo2(void);
int
main(int argc, char **argv) {
foo(&foo2);
return 0;
}
void
foo(void (*name)()) {
(void)printf("in foo\n");
(name)();
return;
}
void
foo2(void) {
(void)printf("in foo2\n");
return;
}