odo odo - 1 year ago 98
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.

Answer Source
  • 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)();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download