odo odo - 2 months ago 9
C Question

What does an asterisk in empty parentheses mean?

What does this c code do?

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

Especially I confused about subj.

  • 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();  


    int var = (*func)();