What will be the output of the following C++ code? [code] #include <iostream> using namespace std; template <typename T = float,

Linh Chi

New member
What will be the output of the following C++ code?
Code:
    #include <iostream>
    using namespace std;
    template <typename T = float, int count = 3>
    T multIt(T x)
    {
        for(int ii = 0; ii < count; ii++)
        {
            x = x * x;
        }
        return x;
    };
    int main()
    {
        float xx = 2.1;
        cout << xx << ": " << multIt<>(xx) << endl;
    }
A. 2.1
B. 378.228
C. 2.1: 378.228
D. 376
 
Answer: c
Explanation: In this program, We specify the type in the template function. We need to compile this program by adding -std=c++0x.
Output:
Code:
$ g++ -std=c++0x spec1.cpp
$ a.out
 

Tìm kiếm

Back
Top