How to print the address of a function with cout in C++? [duplicate]

  c++, functor, memory, pointers

I cannot understand how to print the address of a function in C++:
My simple code is the following:

#include<iostream>

int my_fun () {
          return 5 ; 
} 


int main () {


int (*fp)() = my_fun ; 

std::cout << &fp <<std::endl ; 
std::cout<<my_fun<<std::endl ; 
printf("%pn",my_fun) ; 
std::cout<<(int*)my_fun<<std::endl ; 
}

but I cant understand why the

std::cout<<my_fun<<std::endl ; 

is giving me the number 1 while (int*)my_fun is giving me the right address.
Sorry if the question is trivial.

This is the output of the program:

0x7fffed0713b0
1
0x7ff14f7ca209
0x7ff14f7ca209

Source: Windows Questions C++

LEAVE A COMMENT