2
#include <stdio.h>

// function prototypes
void add(char *name, int x, int y);

// add x + y
void add(char *name, int x, int y) {
  printf("%s gives: %d\n", name, x + y);
}

// calling from main
int main() {

  // some funky function pointer assignment
  void (*add1Ptr)(char*, int, int) = add;
  void (*add2Ptr)(char*, int, int) = *add;
  void (*add3Ptr)(char*, int, int) = &add;
  void (*add4Ptr)(char*, int, int) = **add;
  void (*add5Ptr)(char*, int, int) = ***add;

return 0;

}

In the above code , add is the name of the function so if I want to make a pointer to this add function , why does *add ,**add and ***add return the address of the function add, Since the name of the function itself is an address of the function , so when I dereference it repeatedly , how come it is still able to return the address of the function ? Please explain the logic precisely .

Radha Gogia
  • 765
  • 1
  • 11
  • 22
  • 2
    This is a quirk of the C language for backward compatibility. A dereferenced function pointer turns back to a function pointer when used in an rvalue context. Further discussion here: [How does dereferencing of a function pointer happen?](http://stackoverflow.com/questions/2795575/how-does-dereferencing-of-a-function-pointer-happen) – Raymond Chen Apr 01 '17 at 14:49

0 Answers0