+ 2
Output is 4 how ?
#include <iostream> using namespace std; typedef int (*fpointer)(int,int); int f1(int x,int y){return x+y;} int f2(int x,int y){return x-y;} fpointer getFunc(int x){ if(x==1) return f1; if(x==2) return f2; } int main() { cout<<getFunc(1)(2,2); return 0; }
10 Respostas
+ 13
cout << getFunc(1)(2, 2);
getFunc(1) => x == 1 is true => f1 is returned.
cout << f1(2, 2);
f1(2, 2) => 2 + 2 = 4 is returned.
So, 4 is the output.
+ 2
@krishna Teja yeluripati thanks
+ 2
your name is too long ...
+ 2
#include <iostream>
using namespace std;
int *fun(){
return new int[2];
}
int fun(int*p){
delete[]p;
return 0;
}
void fun (int*p,int q){
p[q]*=2;
}
void fun(int*p,int q,int r){
p[q]=r;
}
int main() {
int *v=fun();
fun(v,0,1);
fun(v,1,2);
fun(v,0);
cout<<v[1]+v[0];
fun(v);
return 0;
}
this program is giving error please find output
+ 1
~swim~ wow awesome very nice explain thank-you very much
0
~swim~ i fixed error now please tell me how to come output 4?