odo odo - 3 months ago 13
C Question

What does an asterisk in empty parentheses mean?

What does this c code do?

{
int (*func)();
func = (int (*)()) code;
(int)(*func)();
}


Especially I confused about subj.

Answer
  • int (*func)(); declares func as a pointer to a function that takes any number of parameters and and return int.

  • In statement func = (int (*)()) code;, a cast is applied to code and then assign it to the function pointer func.

  • (int)(*func)(); doesn't make much sense. Cast is not needed and it discards the return value. The call should be simply like

    int var = func();  
    

    or

    int var = (*func)();
    
Comments