0

I was surprised to find the first two assignments seem to be equivalent - what's going on?

#include "stdio.h"

static int foo() {
  return 3;
}

int main(int argc, char** argv){
  void* fp1 = foo;
  void* fp2 = &foo;

  printf("fp1 is %p\n", fp1);
  printf("fp2 is %p\n", fp2);
}

Sample output:

fp1 is 0x100fd2f70
fp2 is 0x100fd2f70

Why - when assigning to a void* is foo the same as &foo?

eddiewould
  • 1,555
  • 16
  • 36
  • Here's another good one: [Why do function pointer definitions work with any number of ampersands '&' or asterisks '*'?](http://stackoverflow.com/q/6893285/643383) – Caleb Oct 31 '16 at 07:15
  • 1
    What would two different results represent? – M.M Oct 31 '16 at 07:20

0 Answers0