Question
1.
#include
2.
using namespace std;
3.
template
4.
inline T square(T x)
5.
{
6.
T result;
7.
result = x * x;
8.
return result;
9.
};
10.
int main()
11.
{
12.
int i, ii;
13.
float x, xx;
14.
double y, yy;
15.
i = 2;
16.
x = 2.2;
17.
y = 2.2;
18.
ii = square(i);
19.
cout
What is the output of this program?
1.
#include
2.
using namespace std;
3.
template
4.
inline T square(T x)
5.
{
6.
T result;
7.
result = x * x;
8.
return result;
9.
};
10.
int main()
11.
{
12.
int i, ii;
13.
float x, xx;
14.
double y, yy;
15.
i = 2;
16.
x = 2.2;
17.
y = 2.2;
18.
ii = square(i);
19.
cout
Answer: Option C
Was this answer helpful ?
Answer:a
Explanation:In this program, We are passing the values and calculating the square of the value by using the function template.
Output:
$ g++ ftemp4.cpp
$ a.out
2 4
2.2 4.84
Was this answer helpful ?
Submit Solution