-1

I am new to C and pointers (so please go easy on me). I am using a reference book, and I came across these code with no explanations whatsoever (all it said was: a function name is a pointer to that function):

int isBigger(void *a,void *b,int (*f)(void *,void *)){
   return f(a,b)
}

My questions are:

  1. What is void *a?
  2. Is *f a pointer to a function?
  3. What is void *? Is it related to void *a?
MugenTwo
  • 314
  • 6
  • 14

1 Answers1

3

Since the code snippet given would not compile, I assume this is what you meant:

int isBigger(void *a,void *b,int (*f)(void *,void *)){
   return f(a,b);
}

void* is a pointer that can point to anything. See this post for more information.

f is a pointer to a function that takes two void* and returns an int. You can invoke the function with f(a,b). You can find more examples in this post.

Community
  • 1
  • 1
Dafang Cao
  • 897
  • 5
  • 15