I want to pass a function into another function, but I have confused myself so much over the syntax and what is actually happening. This is the code I am running:
#include <stdio.h>
int func(int a){
printf("%d\n", a);
}
void another_func(int p_func(int)){
int (*funcptr)(int) = p_func;
funcptr(7);
}
int main(void){
another_func(func);
return 0;
}
However, I have found out that I can put how many asterix I want before func when calling it in main, for example:
another_func(*******************func);
I can do the same when assigning the function to the function pointer, for example:
int (*funcptr)(int) = ***********p_func;
I am though forbidden to put an ampersand in front of p_func when assigning it to the function pointer. Also it doesn't seem to matter if I write:
void another_func(int (*p_func)(int)){
Can my plead for help wake some of the legendary C gods from their slumber who can make a detailed explanation? I really don't get how this works, what is passed etc.