& operator optional in function pointer assignment

Code:

#include <stdio.h>

int info(int no) {
  printf("no: %d\n", no);
}

int main(int argc, const char *argv[]) {
  int (*fp)(int); 
  fp = info;
  printf("function pointer: %p\n", fp);
  fp = &info;
  printf("function pointer: %p\n", fp);
  return 0;
}
 

 

From the standard (6.3.2.1/4) :

function designator is an expression that has function type. Except when it is the operand of the sizeof operator or the unary & operator, a function designator with type ‘‘function returning type’’ is converted to an expression that has type ‘‘pointer to function returning type’’.

 

Refer to 

http://stackoverflow.com/questions/4298654/operator-optional-in-function-pointer-assignment.

你可能感兴趣的:(function)