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); }

26th Sep 2021, 9:29 AM
Nariman Tajari
Nariman Tajari - avatar
3 Respostas
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?
26th Sep 2021, 10:58 AM
Nariman Tajari
Nariman Tajari - avatar
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() }
26th Sep 2021, 11:17 AM
Ipang