-
What is the output of this program?
#include <iostream>
using namespace std;
template<typename T>
inline T square(T num1)
{
T Res;
Res = num1 * num1;
return Res;
};
int main()
{
int k, kk;
float num1, num2;
double num3, num4;
k = 3;
num1 = 2.3;
num3 = 4.2;
kk = square(k);
cout << k << " " << kk << endl;
num4 = square(num3);
cout << num3 << " " << num4 << endl;
}
-
- 3 9
4.2 17.64 - 4.2 17.64
- 4.2 17.64
3 9 - Compilation Error
- None of these
- 3 9
Correct Option: A
In this program, We are passing the values and calculating the square of the value by using the function template.