2

When I execute the following function, the output addresses for main and &main are the same. Is there any reason why? I don't really understand.

int main()
{
  printf("main=\t0x%08x\n", main);
  printf("&main=\t0x%08x\n", &main);
}
Potato
  • 41
  • 3
  • Can you show the code you used to do this? – Retired Ninja Nov 12 '20 at 03:38
  • When `f` is a function, both `f` and `&f` produce a pointer to the function. It's just how the language works - basically because there's no other sensible thing either one could do, other than maybe being a syntax error. See https://stackoverflow.com/questions/258422/function-pointers-in-c-address-operator-unnecessary. – Nate Eldredge Nov 12 '20 at 03:59
  • 1
    there is one more explanation about this [function address](https://stackoverflow.com/questions/9552663/function-pointers-and-address-of-a-function) – csavvy Nov 12 '20 at 04:02

0 Answers0