I was playing around with function pointers recently, when I discovered that the value of the function pointer as printed by std::cout
always evaluates to 1.
However that was not the case with printf()
, and it prints the expected result.
It'd be great if someone could explain the reason behind such behavior.
Below is the code sample for reference.
#include<iostream>
using namespace std;
int fun(int a)
{
return 0;
}
int main()
{
cout<<(&fun)<<endl; //always prints 1
printf("%u",&fun); //this prints the expected result
return 0;
}