I accidentally printed a function name without the parenthesis and it printed a value. I am just curious about how this happens? Output is same irrespective of the function
std::cout << foo;
Outputs 1
because foo
is a function pointer, it will be converted to bool
with std::cout
.
To print its address, you need explicitly cast it:
std::cout << reinterpret_cast(foo) << std::endl;
With printf("\n%u", foo);
, %u
expects unsigned int
, what you saw is the value of the function pointer converted to unsgigned int
.