#include <iostream>
usingnamespace std;
int pow(int a, int b){
int numb=a;
while (b>0){
cout << numb<<endl;
numb = numb * a;
b--;
}
}
template <class t>
t func(t a, t b){
return (a>b?pow(a,b):pow(b,a));
}
int main(){
int a=2, b=3;
cout << func(a,b)<<endl;
cout << func(b,a)<<endl;
system("pause");
return 0 ;
}
The pow function is for the power operation, a^b, but i am not very sure if i wrote it correctly... In the int main(), I tole the compiler to print out 2 result of the func template with a and b switching their place. But I don't understand why both of them return the same value, and where the 2686724 come from in the result.
The "a>b?<1>:<2>" mean if a larger then b, command 1 will be execute and if a<b, command 2 will be execute right?