0
What is the problem of this code and if we correct this is it possible to take any output from this?
int sum (int a, int b=9) { return a+b;} int main() {int (*psum)(int ,int); psum=*psum; std::cout<<(*psum)(9); }
3 Answers
+ 1
There's no easy way to achieve that, from what I've read from the following links.
https://stackoverflow.com/questions/9760672/howto-c-function-pointer-with-default-values
https://stackoverflow.com/questions/2576411/function-pointers-with-default-parameters-in-c
https://stackoverflow.com/questions/15615174/function-pointer-and-default-argument
0
Ipang the problem is why the psum=*psum; is wrong if someone uses refrences in this code would he/she make the true solution?
0
But what makes you think psum = *psum is corect?
I don't get the relation of references in this matter. What's references got to do with function pointer?
#include <iostream>
int sum( int a )
{
return a * a;
}
int main()
{
// define function pointer <psum> and set it to refer sum() function
int ( *psum )( int ) = sum;
std::cout << psum( 9 ); // invoke sum()
}