+ 1
can someone explain this ?
int sum(int a=2,int b=9){ return a+b; } int main() { int(*psum)(int,int); psum=∑ cout<<*psum; //output1 return 0; }
2 Respuestas
+ 6
You have a function pointer that points to a function which takes 2 ints and returns one, you assign sum to it and print the function without calling it, so you get true/1.
+ 1
Also the reason why it prints 1 is because cout doesn't have an overload for a int(*)(int,int) function pointer.
The next available option is a bool which just converts any address to a 1.
You'd need to overload the specific function pointer yourself for std::ostream operator<< if you want it to print it's actual address.